码迷,mamicode.com
首页 > 其他好文 > 详细

1156求π的值

时间:2017-12-03 18:56:54      阅读:136      评论:0      收藏:0      [点我收藏+]

标签:pow   math   span   cst   space   using   str   main   namespace   

 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求π的值

标签:pow   math   span   cst   space   using   str   main   namespace   

原文地址:http://www.cnblogs.com/tflsnoi/p/7966631.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!