[ create a new paste ] login | about

Link: http://codepad.org/jcH26oji    [ raw code | output | fork ]

C, pasted on Jan 20:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <stdio.h>
#include <math.h>
 
int main(void)
{
    double eps = 1.e-5;
    double sum = 0;
    double an =1;

    while( fabs(an) > eps )
    {
        sum += an;
        an = -an/2;
    }
    printf("series\t%f\tcorrect\t%f\n", sum, 2./3.);
    return 0;
}


Output:
1
series	0.666672	correct	0.666667


Create a new paste based on this one


Comments: