Program to Calculate e ^ x by Recursion ( using Taylor Series ) | C # implementation of the approach ; Recursive Function with static variables p and f ; Termination condition ; Recursive call ; Update the power of x ; Factorial ; Driver code
using System ; class GFG { static double p = 1 , f = 1 ; static double e ( int x , int n ) { double r ; if ( n == 0 ) return 1 ; r = e ( x , n - 1 ) ; p = p * x ; f = f * n ; return ( r + p / f ) ; } static void Main ( ) { int x = 4 , n = 15 ; Console . WriteLine ( Math . Round ( e ( x , n ) , 6 ) ) ; } }