Example 27: Evaluate Exponential Series

Learn how to evaluate an exponential series.

Problem

The exponential function exe^{x} is defined as the sum of the following series:

1+x+(x22!)+(x33!)+(x44!)+....1+x+(\frac{x^{2}}{2!})+(\frac{x^{3}}{3!})+(\frac{x^{4}}{4!})+....

If xx is an input to a function, write a program to calculate the sum of the first ten terms of the series.

Example

Inputs Outputs
-4 0.096719
0 1.000000
1.5 4.481686
3 20.079666
5 146.380615

Try it yourself

Try to solve this question on your own in the code widget below. If you get stuck, you can always refer to the solution provided.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.