根据PI/4 = 1 - 1/3 +1/5-1/7+1/9..............
#include<stdio.h>
#include<math.h>
void main()
{
double sum = 1;
double temp;
int sign = -1;
int n = 2;
float pi;
while(fabs(temp) > 1e-7)
{
temp = (2*n-1)*sign;
sign = -sign;
temp = 1/temp;
sum+=temp;
n++;
}
pi = sum*4;
printf("圆周率是:%lf/n",pi);
}