program will approximate the value of e...when x=5.7.. but i am not getting the result right . could anybody help me and show my mistake please...
when the difference between two successive approximations is less tan 10e-9
Without that change I get an error C2668. BTW: If the compiler would tolerate the wrong statement, it would even work, since e is approached from below...
But I had to make some more changes to your program to actually compile and correctly calculate the (approximate) value of e. And only that way it matches the approximation formula from post #1. Here is the corrected version, with the changes marked in red:
using namespace std;
double /* x, */myexp1,myexp2,expx,fact,i;
output<<" ..... "<<endl;
// x=5.7; // That's not needed anymore
cout << setprecision(12); // In order to see all changes up to the last iteration
output << setprecision(12); // ditto
while (fabs(expx-myexp1) >= 10e-9)
cout<< "..... " <<"i= "<<expx<<endl;
output<< ".... " <<"i= "<<expx<<endl;
I hope I didn't miss any change.
... And I hope this wasn't homework I now have done for you...
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.