用C语言如何编程求出"派“的值(3.141592654......)

2025-06-26 11:41:52
推荐回答(4个)
回答1:

#include
#include

int main(int argc, char* argv[])
{
int s;
float n,t,pi;
t = 1.0;
pi = 0;
n=1.0;
s = 1;

while(fabs(t) >= 1e-6)
{
pi = pi + t;
n = n + 2.0f;
s = -s;
t = s / n;
}

pi = pi * 4;

printf("pi=%f\n",pi);

return 0;

}

回答2:

这个你可以采用不同的算法实现。如刘徽割圆法,幂级数法、数值积分法等。

回答3:

#include
#include

int main()
{
double PI = 2*acos(0);
printf("%lf\n",PI);
return 0;

}

回答4:

#include

long a=10000,b,c=2800,d,e,f[2801],g;
int main()
{

for(;b-c;)f[b++]=a/5;
for(;d=0,g=c*2;c-=14,printf("%.4d",e+d/a),e=d%a)
for(b=c; d+=f[b]*a, f[b]=d%--g, d/=g--, --b; d*=b);
return 0;
}