/* 计算圆周率值 */
#include<stdio.h>
int main()
{
double PI = 0.0;
double d = 1.0;
int sig = 1;
double item =4.0*1.0 /d*sig;
while(fabs(item) >= 1e-6)
{
PI += item;
d += 2;
sig *= -1;
item =4.0*1.0 /d*sig;
}
printf("%.5f\n",PI);
}
/* 计算圆周率值 */
#include<stdio.h>
int main()
{
double PI = 0.0;
double d = 1.0;
int sig = 1;
double item =4.0*1.0 /d*sig;
while(fabs(item) >= 1e-6)
{
PI += item;
d += 2;
sig *= -1;
item =4.0*1.0 /d*sig;
}
printf("%.5f\n",PI);
}