#include <stdio.h>
#include <math.h>
main()
{
int i,f;
double t,s;
f=1;
s=0;
i=1;
t=1.0;
while(t>=1e-5)
{
s=s+t*f;
f=-f;
t=1.0/(2*i+1);
i++;
}
s=s*4;
printf("圆周率的近似值为:%.10f\n",s);
}
C语言:编程计算π的近似值(直到最后一项的绝对值小于10-5为止),要求保留小数点后10位。
最新推荐文章于 2024-12-14 15:44:04 发布