#include <iostream>
#include <iomanip>
using namespace std;
#include <math.h>
void Seriessummation(int n, int j)
{
int i, k;
double ans = 0.0, m, pi, P;
pi = acos(-1);
for (i = 1, k = 1; k <= n; i += j)
{
m = 4.0 / i;
if (k % 2 == 1)
ans = ans + m;
else
ans = ans - m;
k++;
}
if (n <= 100)
cout << setw(12) << setprecision(11) << ans << endl;
else
{
P = (pi - ans) / pi * 100;
cout << setw(12) << setprecision(11) << ans;
if (n == 50000)
cout << setiosflags(ios::fixed) << setprecision(6) << " " << P << "%" << endl;
else
cout << setiosflags(ios::fixed) << setprecision(6) << " " << P << "%" << endl;
}
}
int main()
{
cout << " 纯手工原创打造" << endl;
int n, j;
double ans;
cout << "NO.1: " << endl
<< endl;
n = 12;
j = 2;
Seriessummation(12, 2);
cout << "________________________________________" << endl;
cout << endl;
cout << "NO.2: " << endl;
for (n = 50000; n <= 1000000; n = n + 50000)
Seriessummation(n, j);
return 0;
}