Efficient program to calculate e ^ x | Java efficient program to calculate e raise to the power x ; Function returns approximate value of e ^ x using sum of first n terms of Taylor Series ; initialize sum of series ; driver program
import java . io . * ; class GFG { static float exponential ( int n , float x ) { float sum = 1 ; for ( int i = n - 1 ; i > 0 ; -- i ) sum = 1 + x * sum / i ; return sum ; } public static void main ( String [ ] args ) { int n = 10 ; float x = 1 ; System . out . println ( " e ^ x ▁ = ▁ " + exponential ( n , x ) ) ; } }