Find N numbers such that a number and its reverse are divisible by sum of its digits | Function to calculate the sum of digits ; Loop to iterate through every digit of the number ; Returning the sum of digits ; Function to calculate the reverse of a number ; Loop to calculate the reverse of the number ; Return the reverse of the number ; Function to print the first N numbers such that every number and the reverse of the number is divisible by its sum of digits ; Loop to continuously check and generate number until there are n outputs ; Variable to hold the sum of the digit of the number ; Computing the reverse of the number ; Checking if the condition satisfies . Increment the count and print the number if it satisfies . ; Driver code
function digit_sum ( n ) { let sum = 0 , m ; while ( n > 0 ) { m = n % 10 ; sum = sum + m ; n = parseInt ( n / 10 , 10 ) ; } return ( sum ) ; } function reverse ( n ) { let r = 0 ; while ( n != 0 ) { r = r * 10 ; r = r + n % 10 ; n = parseInt ( n / 10 , 10 ) ; } return ( r ) ; } function operation ( n ) { let i = 1 , a , count = 0 , r ; while ( count < n ) { a = digit_sum ( i ) ; r = reverse ( i ) ; if ( i % a == 0 && r % a == 0 ) { document . write ( i + " " ) ; count ++ ; i ++ ; } else i ++ ; } } let n = 10 ; operation ( n ) ;