Sum of the series Kn + ( K ( n | Function to return sum ; Driver code
function sum ( k , n ) { let sum = 0 ; for ( let i = 0 ; i <= n ; i ++ ) { let p = 1 ; for ( let j = 0 ; j < n - i ; j ++ ) { p = p * k ; } for ( let j = 0 ; j < i ; j ++ ) { p = p * ( k - 1 ) ; } sum = sum + p ; } return sum ; } let n = 3 ; let K = 3 ; document . write ( sum ( K , n ) ) ;