题目
代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
double pai = 0;
for (int count = 1, i = 1; count <= 1000; i += 2, count++)
{
int flag = 1;
if (count % 2 == 0)
{
flag = -1;
}
pai += flag * (4.0 / (i * 1.0));
cout << "当取前" << count << "项时,Π近似值为" <<setprecision(15)<< pai << endl;
}
return 0;
}