求π的值,已知π/4≈1-1/3+1/5-1/7+ . ..计算至某项的绝对值小于IE-6为止.有没有同志帮帮我,谢谢!
#include <stdio.h>
#include <math.h>
int main ()
{
double PI=0.0,a=1.0,term=1.0;
int sign=1;
while(fabs(term)>=1e-6)
{
PI+=term;
a=a+2;
sign=-sign;
term=sign/a;
}
PI=PI*4;
printf("PI=%10.8f\n",PI);
return 0;
}