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
- Write a program to calculate pow(x,n)
- Write a program to reverse digits of a number
- Efficient way to multiply with 7
- Program to find whether a no is power of two
- Write an Efficient Method to Check if a Number is Multiple of 3
- Program to find parity
- Write an Efficient C Program to Reverse Bits of a Number
- Write a program to print all permutations of a given string
- Write a program to add two numbers in base 14
- Program for Fibonacci numbers
- Space and time efficient Binomial Coefficient
- Program to find amount of water in a given glass
- Program to convert a given number to words
- Efficient program to print all prime factors of a given number
- Program for nth Catalan Number