Program to Calculate e ^ x by Recursion ( using Taylor Series ) | Recursive Function with static variables p and f ; Termination condition ; Recursive call ; Update the power of x ; Factorial ; Driver Code
p = 1 , f = 1 ; function e ( x , n ) { var r ; if ( n == 0 ) return 1 ; r = e ( x , n - 1 ) ; p = p * x ; f = f * n ; return ( r + p / f ) ; } var x = 4 , n = 15 ; var res = e ( x , n ) ; document . write ( res . toFixed ( 6 ) ) ;