求π的近似值
程序员文章站
2022-07-07 18:36:41
...
#include<bits/stdc++.h>
double funpi(double n)
{
double w = 0,item = 1,flag=1,denominator=1;
while(fabs(item)>=n){
item = flag*1.0/denominator;
w = w+item;
flag = -flag;
denominator = denominator + 2;
}
return 4*w;
}
int main()
{
double pi,e;
scanf("%lf",&e);
pi = funpi(e);
printf("pi = %lf",pi);
return 0;
}
上一篇: 前端网站安全问题
下一篇: Centos7.3安装Composer