当前位置: > 使用C++,求pi的近似值...
题目
使用C++,求pi的近似值
用下面的公式求pi的近似值
pi/4 = 1-1/3+1/5-1/7+.
直到最后一项的绝对值小于10的-7次方为止
如下式我自己编的
#include "stdafx.h"
#include "iostream"
#include "cmath"
#include "conio.h"
using namespace std;
int _tmain(int argc,_TCHAR* argv[])
{
int n = 1;
double P = 0,pi;
for(n=1;1/(2*n-1) < 10^(-7);++n)
{
P += ((-1)^(n+1))*(1/(2*n-1));
}
pi = P*4;
cout

提问时间:2020-05-30

答案
才疏学浅,你的程序好多看不到,我挑主要的for循环中的说:#include "iostream"#include "math.h"using namespace std;void main(){int n = 1;double P = 0,pi;for(n=1;pow((2*n-1),(-1))>pow(10,(-7));n++) //pow()的...
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
版权所有 CopyRight © 2012-2019 超级试练试题库 All Rights Reserved.