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...
x=1+1/1!+1/2!+1/3!+1/4!+1/5!+.......
when the difference between two successive approximations is less tan 10e-9
Code:int main() { double x,myexp1,myexp2,expx,fact,i; fact=1; ofstream output("e:result12.dat"); cout<<" ....."<<endl; output<<" ..... "<<endl; x=5.7; myexp1=1; myexp2=x; i=2; expx=myexp1+myexp2; while (fabs(expx-myexp1 >= 10e-9)) { fact=fact*1; myexp1=expx; expx=expx+pow(x,i)/fact; i=i+1; cout<< "..... " <<"i= "<<expx<<endl; output<< ".... " <<"i= "<<expx<<endl; } system("PAUSE"); return 0; }




Reply With Quote