Answer to Question #8679 in C++ for niloofar

Question #8679
How can I write a program that calculates : e^x = 1+x/1!+x^2/2!+x^3/3!+...
1
Expert's answer
2012-04-24T09:51:53-0400
#include <iostream>
#include <cmath>
using namespace std;

void main(){

double x, r=1;

printf("Enter x value: ");
cin>>x;

for (int n=1;n<10;n++){
& int f = 1;
& for (int i=1;i<=n;i++) f = f*i;
& r += pow(x,n)/f;
}

printf("e^%f = %f\n", x, r);

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS