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
30
31
32
33
34
35
36
#include <iostream>
#include <stdlib.h>
#include <cmath>
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;
std::cout << "SubValue: " << seriesTaylor(1, 250) << std::endl;
std::cout << "SubValue: " << seriesTaylor(250, 500) << std::endl;
std::cout << "SubValue: " << seriesTaylor(500, 750) << std::endl;
std::cout << "SubValue: " << seriesTaylor(750, 1000) << std::endl;
}