快速收敛的圆周率计算(函数和for循环):编写函数ComputePi()求π(使用pi作为变量)的值,求值的公式为 要求:(1)ComputePi函数在完成精度达到0.00001;(2)公式中红色部分也用函数表示。请编写程序,调用该函数并输出每一次迭代的结果,并指出第几项就达到精度0.00001?
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x = 0, y = 1, s = 1, t = 1;
int h = 0, n = 0;
while (x <= (2^29))
{
h = 0;
while ( h <= n)
{
x = x + 1;
y = y + 2;
t = t * (x / y);
h = h +1;
}
s = s + t;
}
y = 2 * s;
cout << y << endl;
return 0;
}
如果对你有帮助,可以给我个采纳吗,谢谢!!