我的尝试
#include <iostream>
#include <iomanip>
using namespace std;
double myE(int num);
int main(){
double e = myE(10);
cout<<"e is "<<fixed<<showpoint<<setprecision(5)<<e<<endl;
return 0;
}
double myE(int num){
double e = 0;
double factorial = 1;
int x;
cout<<"Enter a value for x in the expression e^x:"<<endl;
cin>>x;
for(int j = 0; j <= num; j++){
for(int i = 1; i <= j; i++){
factorial = factorial * i;
}
for(int k = 0; k <= x; k++){
e = e + x / factorial;
factorial = 1;
}}
return e;
}
我一直得到错误的答案..我做错了什么