Find the first N integers such that the sum of their digits is equal to 10 | Function to return the sum of digits of n ; Add the last digit to the sum ; Remove last digit ; Return the sum of digits ; Function to prvar the first n numbers whose sum of digits is 10 ; First number of the series is 19 ; If the sum of digits of the current number is equal to 10 ; Print the number ; Add 9 to the previous number ; Driver code
function sum ( n ) { var sum = 0 ; while ( n > 0 ) { sum = sum + n % 10 ; n = parseInt ( n / 10 ) ; } return sum ; } function firstN ( n ) { var num = 19 , cnt = 1 ; while ( cnt != n ) { if ( sum ( num ) == 10 ) { document . write ( num + " " ) ; cnt ++ ; } num += 9 ; } } var n = 10 ; firstN ( n ) ;