I am having trouble using these long doubles, I can not get them to work properly at all, I keep getting 1 for sum1 and 0 for sum2. I was just curious could give me a hint at where I am going wrong with this.
Code:#include<stdio.h> #include<stdlib.h> int main(void) { long double sum1, sum2, pi; int i, j; sum1 = 0; sum2 = 0; for (i = 1; i <= 99; i+=4) sum1 = sum1 + (1 / i); printf("%Lf\n", sum1); for (j = 3; j <= 99; j+=4) sum2 = sum2 + (1 / j); printf("%Lf\n", sum2); pi = 4 * (sum1 - sum2); printf("pi = %Lf\n", pi); return 0; }



LinkBack URL
About LinkBacks


