1 //编写一个C++程序求PI的值 2 /* 3 PI=16arctan(1/5)-4arctan(1/239) 4 其中arctan用如下形式的极数计算: 5 arctan=x-(x^3/3)+(x^5/7)-(x^7/7)+... 6 */ 7 #include<iostream> 8 using namespace std; 9 double arctan(double x){ 10 double sqr = x*x; 11 double e = x; 12 double r = 0; 13 int i = 1; 14 while(e/i>1e-16){ 15 double f = e/i; 16 r = (i%4==1)?r+f:r-f; 17 e = e*sqr; 18 i+=2; 19 } 20 return r; 21 } 22 int main() 23 { 24 double a = 16.0*arctan(1/5.0); 25 double b = 4.0*arctan(1/239.0); 26 cout<<"PI="<<a-b<<endl; 27 system("pause"); 28 return 0; 29 }
《用C++语言编写一个程序,求PI的值》
原创
©著作权归作者所有:来自51CTO博客作者mb61289d0fd3618的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:《JAVA学习笔记(14-10---14-11抽象类)》
下一篇:《二叉树的练习》
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
C语言求PI的值
通过简单的方法求出我们的PI的值
C语言 PI的值 循环控制 -
求Pi的方法总结
古今中外,求Pi的方法主要有三类主要的方法:1,正多边形逼近法2,迭代法(级数法)3,蒙特卡
#include 迭代法 函数定义 -
C++求平均年龄
C++求平均年龄
#include ios 其他 -
求C++技术帮助新手
寻c++技术长期答疑解惑大一新生
c++ 寻c++技术求助 -
Actuator写入Prometheus
Redis exporter使用 Prometheus 进行 Redis 监控的都知道,Redis_exporter 是较常用的解决方案,但是在 redis_exporter 开始的版本中,并不支持一个 redis_exporter 实例监控多 Redis 实例,这样造成 exp
redis java-consul prometheus docker Redis