e^x = 1 + x/1! + x^2/2! + x^3/3! + ......
How to efficiently calculate the sum of above series?
The series can be re-written as
e^x = 1 + (x/1) (1 + (x/2) (1 + (x/3) (........) ) )
Let the sum needs to be calculated for n terms, we can calculate sum using following loop.
for (i = n - 1, sum = 1; i > 0; --i ) sum = 1 + x * sum / i;
Following is implementation of the above idea.
e^x = 2.718282
This article is compiled by Rahul and reviewed by GeeksforGeeks team. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Efficient Program to Compute Sum of Series 1/1! + 1/2! + 1/3! + 1/4! + .. + 1/n!
- Efficient program to print the number of factors of n numbers
- Write an Efficient C Program to Reverse Bits of a Number
- Efficient program to print all prime factors of a given number
- Java Program for Program to calculate area of a Tetrahedron
- Python Program for Program to calculate area of a Tetrahedron
- C program to calculate the value of nPr
- C Program to calculate the value of sin(x) and cos(x)
- Program to calculate value of nCr
- Program to calculate age
- Program to calculate the value of nCr Efficiently
- Write a program to calculate pow(x,n)
- Program to calculate distance between two points in 3 D
- Program to Calculate the Perimeter of a Decagon
- Program to calculate area of Enneagon