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!+...
Expert's answer
#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);
}
#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 orderand get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Comments
Leave a comment