Program to find sum of 1 + x / 2 ! + x ^ 2 / 3 ! + ... + x ^ n / ( n + 1 ) ! | Function to find the factorial of a number ; Function to compute the sum ; Iterate the loop till n and compute the formula ; Get x and n ; Print output
< ? php function fact ( $ n ) { if ( $ n == 1 ) return 1 ; return $ n * fact ( $ n - 1 ) ; } function sum ( $ x , $ n ) { $ total = 1.0 ; for ( $ i = 1 ; $ i <= $ n ; $ i ++ ) { $ total = $ total + ( pow ( $ x , $ i ) / fact ( $ i + 1 ) ) ; } return $ total ; } $ x = 5 ; $ n = 4 ; echo " Sum ▁ is : ▁ " , sum ( $ x , $ n ) ; ? >