Find the smallest number whose sum of digits is N | Function to get sum of digits ; Function to find the smallest number whose sum of digits is also N ; Checking if number has sum of digits = N ; Driver code
function getSum ( n ) { let sum = 0 ; while ( n != 0 ) { sum = sum + n % 10 ; n = Math . floor ( n / 10 ) ; } return sum ; } function smallestNumber ( N ) { let i = 1 ; while ( 1 ) { if ( getSum ( i ) == N ) { document . write ( i ) ; break ; } i ++ ; } } let N = 10 ; smallestNumber ( N ) ;