标签:e^x
#include<iostream> #include<cmath> using namespace std; double fac(int n) { if(0 == n) return 1; else if(1 == n) return 1; else return n*fac(n-1); } int main() { double x,sum; char ans; do { cout<<"Please input the x :\n"; cin>>x; cout<<"The e^x = "<<exp(x)<<endl; for(int n = 1;n < 100;n++) { sum = 0; for(int i = 0;i <= n;i++) { sum += pow(x,i)/fac(i); } if(n % 10 == 0) cout<<"The result is "<<sum<<endl; else cout<<"The result is "<<sum<<" ; "; } cout<<endl<<"Do you want again?"; cin>>ans; }while(‘y‘ == ans || ‘Y‘ == ans); return 0; }
求e^x的值,输入x。
标签:e^x
原文地址:http://9320314.blog.51cto.com/9310314/1544740