include iostream include stdlib include cmath double seriesTaylor int

 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
#include <iostream>
#include <stdlib.h>
#include <cmath>
double seriesTaylor(int start, int endN)
{
std::cout << start << " " << endN << std::endl;
double a = 0.;
for (int i = start + 1; i <= endN; i++)
a += (double)(pow(-1, i) / (i + 2.0));
std::cout << a << std::endl << std::endl;
return a;
}
int main(int argc, char *argv[])
{
double d = 1;
d += seriesTaylor(0, 250);
d += seriesTaylor(250, 500);
d += seriesTaylor(500, 750);
d += seriesTaylor(750, 1000);
std::cout << d * 4 << std::endl;
}