开发者社区> 问答> 正文

求助:c++求pi,编译通过,但运行后无任何结果?

screenshot

#include "stdafx.h"
#include
using namespace std;
int main()
{
double arctan(double);
cout << "pi= " << 16 * arctan(1 / 5.0) - 4 * arctan(1 / 239.0) << endl;
return 0;
}
double arctan(double x)
{
double result = 0;
int i = 1, k = 1;
do
{
for (k = 1; k <= (2 * i - 1); k++)
k *= x;
switch (i % 2)
{
case 1:
result += (k / (2 * i - 1)); break;
case 0:
result -= (k / (2 * i - 1)); break;
}
i++;
} while (k > 1e-15);
return result;
}

展开
收起
a123456678 2016-03-09 10:48:42 1899 0
1 条回答
写回答
取消 提交回答
  •  #include<iostream>
    using namespace std;
    
    double arctan(double);
    
    int main()
    {
        cout << "pi= " << 16 * arctan(1 / 5.0) - 4 * arctan(1 / 239.0) << endl;
        return 0;
    }
    
    double arctan(double x)
    {
        double result = 0;
        int i = 1, s = 1;
            double k = 1.0;
        do
        {
            double t = 1;
            for (int j = 0; j < (i * 2 - 1); j++)
                t *= x;
                    k = t / (double)(i * 2 - 1) * (double)s;
            result = result + k;
            s = -s;
            i++;
        } while (k > 1e-15);
        return result;
    }
    2019-07-17 18:55:34
    赞同 展开评论 打赏
问答分类:
C++
问答地址:
问答排行榜
最热
最新

相关电子书

更多
使用C++11开发PHP7扩展 立即下载
GPON Class C++ SFP O;T Transce 立即下载
GPON Class C++ SFP OLT Transce 立即下载