The following code should output: 2.000000, but it gives -0.000000. Where exactly I am getting things wrong?
#include <stdio.h>
#include <math.h>
int main(int argc, char const *argv[]) {
// number of iterations = k.
int k = 100;
long double sum = 0;
for (int n = 0; n < k; n++)
sum += 1 / pow(2, n);
printf("series sum = %lf", sum);
return 0;
}