Program to find Sum of a Series a ^ 1 / 1 ! + a ^ 2 / 2 ! + a ^ 3 / 3 ! + a ^ 4 / 4 ! + Ã ¢ â ‚¬¦ Ã ¢ â ‚¬¦ . + a ^ n / n ! | function to calculate sum of given series ; multiply ( a / i ) to previous term ; store result in res ; Driver Function
function sumOfSeries ( a , num ) { let res = 0 , prev = 1 ; for ( let i = 1 ; i <= num ; i ++ ) { prev *= ( a / i ) ; res = res + prev ; } return ( res ) ; } let n = 5 , a = 2 ; document . write ( sumOfSeries ( a , n ) ) ;