Im having trouble trying to figure out how to modify my PI program below:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double pi= 0;
int accuracy = 2000;
for (long double i=1; i<=accuracy; i++)
{
pi += (long double) pow(-1, i+1)/(2*i-1);
}
pi *= 4;
cout.precision(15);
cout << "My best approximation of PI is: " << pi <<endl;
system("PAUSE");
return 0;
}
What I want to modify is to have have the program run its loop 2000 times & get a result & then 1999 times & get a result. I then want take the average of the two results & output that average. Any help is appreciated.
Thanks
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double pi= 0;
int accuracy = 2000;
for (long double i=1; i<=accuracy; i++)
{
pi += (long double) pow(-1, i+1)/(2*i-1);
}
pi *= 4;
cout.precision(15);
cout << "My best approximation of PI is: " << pi <<endl;
system("PAUSE");
return 0;
}
What I want to modify is to have have the program run its loop 2000 times & get a result & then 1999 times & get a result. I then want take the average of the two results & output that average. Any help is appreciated.
Thanks