Sum of all N digit palindrome numbers | Function to calculate sum of n digit number ; Corner case ; Using above approach ; Driver code
function getSum ( n ) { var sum = 0 ; if ( n == 1 ) { sum = 45.0 ; } else { sum = ( 99.0 / 2.0 ) * Math . pow ( 10 , n - 1 ) * Math . pow ( 10 , parseInt ( ( n - 1 ) / 2 ) ) ; } return sum ; } var n = 3 ; var ans = getSum ( n ) ; document . write ( ans + " " ) ;