Program to find sum of 1 + x / 2 ! + x ^ 2 / 3 ! + ... + x ^ n / ( n + 1 ) ! | Function to compute the series sum ; To store the value of S [ i - 1 ] ; Iterate over n to store sum in total ; Update previous with S [ i ] ; Get x and n ; Find and print the sum
function sum ( x , n ) { let total = 1.0 ; let previous = 1.0 ; for ( let i = 1 ; i <= n ; i ++ ) { previous = ( ( previous * x ) / ( i + 1 ) ) ; total = total + previous ; } return total ; } let x = 5 , n = 4 ; document . write ( " " + sum ( x , n ) ) ;