Hi everyone I am trying to write a program that calculates pi.
So far my program looks like this:
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
long double pi = 2.0;
int i = 1;
for (int n = 2; fabs(pi - 3.1416) > 0.0001; n+=2)
{
pi *= (n/(n-1.)) * (n/(n+1.));
i++;
cout << "i = " << i << "\tpi = " << pi << endl;
}
return 0;
}
Here's the catch - my professor only wants us to be as precise as 3.1416 - How the heck would I do that - I have tried everything and I am out of ideas???? He told us it would take between 600 and 700 iterations - I was going into the millions so I am doing something wrong...any ideas? Please help...I hate Pi.