Sum of digits of a given number to a given power | Function to calculate sum ; Driver Code
function calculate ( n , power ) { sum = 0 ; bp = Math . pow ( n , power ) ; while ( bp != 0 ) { d = bp % 10 ; sum = sum + d ; bp = Math . floor ( bp / 10 ) ; } return sum ; } n = 5 ; power = 4 ; document . write ( calculate ( n , power ) ) ;