Write your question here.
//Mathematician Gottfried Wilhelm Leibnitz wrote this equation to estimate pi, pi = sqrt(12)*(1-(1/(3*3)+(1/(5*3^2)-(1/(7*3^3))+G , with G as the number of iterations. Essentially what the question is asking of me is to code a program that prompts the user to enter tolerance, use a while loop to converge on solution to 'equal' pi within tolerance and the least number of iterations possible.
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
usingnamespace std;
constdouble MPi =3.141592653589793238463;
double Pi_est, Tol, G; //estimate, Tolerance, G is the iteration increase
int i,p,j, k; // the interations increases except k which the iteration counter
int main(int nNumberofArgs, char*pszArgs[]){
cout<<"Please enter desired tolerance 'any whole interger': ";
cin>>Tol;
Tol = Tol/10;
cout<<MPi;
for(k=0;k<100;k++){ //for counter loop
cout<<k; // to check loop
while (Tol < abs((Pi_est-MPi)/MPi)){ // while equation not within tolerances
} for (i = 3;i<MPi;i++){
}
for ( j=7;j<15;j++){
}
for ( p = 3;p<6;p++){
}
if (Tol > abs((Pi_est-MPi)/MPi)){
break;
if(Tol != abs((Pi_est-MPi)/MPi)){
G =(1/(j+i^p));
} else
Pi_est = sqrt(12)*(1-(1/9)+(1/45)-(1/(7*27) + G));
}
if (k>10){
cout<<"this is tolerance"<<Tol<<endl;
cout<<"the is the estimate"<<Pi_est<<endl;
break;}
cout<<"this is the iterations";
return k;
}
}
this is what I have so far, the problem I am having is that the execution problem freezes and will not complete the loop. My guess is that it can't due to the fact the Tolerance is never reached, I'm not sure. I also apologize for any grammar or spelling errors.
To be fair, there are a lot of iterative equations for estimating pi so it is no guarantee that just because it isn't near the top of google, it isn't valid.