Series function

How can do e^x sum series by using function?
Last edited on
Quite simple really.

You use the function called std::exp();

1
2
const double EulersNumber = std::exp(x); // x can be whatever number you want it to be. 
                                         // if x was for example 2. You would get e^2. 
Last edited on
no i want to do this series x^0/0!+x^1/1!+x^2/2!+.........
You're gonna want:
1. The pow function, to calculate X^N,
2. A function that can compute the Nth factorial.
3. A for loop to iterate through through the pattern you posted.

Split it into checkable parts - first make sure you have a correct factorial(N) function, then work on the pattern inside your for loop, and keep track of it with a sum variable.

Here's a good start:
sum += pow(x, N) / factorial(N);

Edit: Yep, as fg109 has pointed out, I agree JLBorges' solution is much better.
Last edited on
Topic archived. No new replies allowed.