1. 程式人生 > >1156求π的值

1156求π的值

namespace while 問題 strong pre clu pow using 代碼

 1 #include<cstdio>
 2 #include<cmath>
 3 using namespace std;
 4 double at(double x)
 5 {
 6     double sum=0;
 7     int n=1,t=1;
 8     double s;
 9     while(s>=1e-6)
10     {
11         s=pow(x,n)/n;
12         s=s*t;
13         sum+=s;
14         t=t*(-1);
15         n=n+2;
16     }
17 18 return sum; 19 } 20 int main() 21 { 22 double pi; 23 pi=6*at(1/sqrt(3)); 24 printf("%lf",pi); 25 return 0; 26 }

大家貓貓這個代碼有沒有問題?怎麽改?

1156求π的值