/* compute e^x using the first 5 terms of the series. */ #include #include using namespace std; double approx(double); int fact(int); int main( ) { double x; cout << "Enter the value of x: "<> x; cout << "The value of e^x using C++ library function is: " << exp(x) << endl; cout << "The value of e^x using the first 5 terms of the series is: " << approx(x) << endl; return 0; } double approx(double x) //compute e^x using the first 5 terms of the series { double y; y = 1.0 + x + pow(x,2)/fact(2) + pow(x,3)/fact(3) + pow(x,4)/fact(4); return y; } int fact(int n) // compute n! { int nfact=1; while (n>1) {nfact = nfact * n; n--; } return nfact; }