天天看点

NOJ:计算Π

NOJ:计算Π
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main()
{
    double a,low;
    int i;
    double x,y,ans;
    a=low=1.0;
    x=1;
   while(fabs(a/low)>=0.0000001)
    {
        a=-a;
        low=low+2;
        x=x+a/low;
       }

    ans = 4.0*x;
    printf("%.6lf\n",ans);
    return 0;
}