作业帮 > 综合 > 作业

怎样用c语言编写求PI的近似值?

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/11 04:32:45
怎样用c语言编写求PI的近似值?
使用格里高利公式求PI的近似值要求精确到最后一项的绝对值小于10的负4次方?
#include
#include
main()
{
double t,pi;
long int n,s;
t=1.0;
n=1;
s=1;
pi=0.0;
while (fabs(t)>=1e-6)
{
pi=pi+t;
n=n+2;
s=-s;
t=(float)(s)/(float)(n);
}
pi=pi*4;
printf(" pi=%lf\n",pi);
}