Efficient program to calculate e ^ x | Function returns approximate value of e ^ x using sum of first n terms of Taylor Series ; initialize sum of series ; driver program
function exponential ( n , x ) { var sum = 1 ; for ( i = n - 1 ; i > 0 ; -- i ) sum = 1 + x * sum / i ; return sum ; } var n = 10 ; var x = 1 ; document . write ( " " + exponential ( n , x ) . toFixed ( 6 ) ) ;