double seriesTaylor int start int endN std cout start endN std endl in

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
double seriesTaylor(int start, int endN)
{
std::cout << start << " " << endN << std::endl;
int i = start;
int n = endN;
double a = 1.;
double d = 0., f = 0.;
double pi = 0.;
for (i; i <= n; i++)
{
d = (double)1/(i+2);
f = (double)pow(-1, i) * d;
a += f;
}
pi = 4*a;
std::cout << pi << std::endl;
return pi;
}
int main (int argc, char *argv[])
{
double d = 0;
d += seriesTaylor(1, 250);
d += seriesTaylor(250, 500);
d += seriesTaylor(500, 750);
d += seriesTaylor(750, 1000);
std::cout << d << std::endl;
std::cout << seriesTaylor(1, 1000) << std::endl;
}