Skip to content

Instantly share code, notes, and snippets.

@adityasuseno
Created September 6, 2020 14:23
Show Gist options
  • Save adityasuseno/60dfef79bdbfd88780f6956bd6aec701 to your computer and use it in GitHub Desktop.
Save adityasuseno/60dfef79bdbfd88780f6956bd6aec701 to your computer and use it in GitHub Desktop.
Aplikasi untuk menghitung 1 + 1/2 + 1/3 + 1/4 + 1/5 + ... + 1/N
/* Aplikasi untuk menghitung 1 + 1/2 + 1/3 + 1/4 + 1/5 + ... + 1/N */
#include<stdio.h>
int main()
{
unsigned long long N;
/*read value of N*/
printf("Masukan Jumlah N: ");
scanf("%llu",&N);
/*set sum by 0*/
long double sum=0.0f;
unsigned long long i;
/*calculate sum of the series*/
for(i=1;i<=N;i++)
sum = sum + ((float)1/(float)i);
/*print the sum*/
printf("Hasil: %Lf\n",sum);
return 0;
}
# Aplikasi untuk menghitung 1 + 1/2 + 1/3 + 1/4 + 1/5 + ... + 1/N
print("Masukan Jumlah Iterasi: ")
N = parse(UInt64, readline())
function sum_to(N)
jumlah::Float64 = 0
for i = 1:N
jumlah = jumlah + (1/i)
end
println(jumlah)
end
sum_to(N)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment