Find all palindrome numbers of given digits | Function to return the reverse of num ; Function that returns true if num is palindrome ; If the number is equal to the reverse of it then it is a palindrome ; Function to print all the d - digit palindrome numbers ; Smallest and the largest d - digit numbers ; Starting from the smallest d - digit number till the largest ; If the current number is palindrome ; Driver code
function reverse ( num ) { let rev = 0 ; while ( num > 0 ) { rev = rev * 10 + num % 10 ; num = parseInt ( num / 10 , 10 ) ; } return rev ; } function isPalindrome ( num ) { if ( num == reverse ( num ) ) return true ; return false ; } function printPalindromes ( d ) { if ( d <= 0 ) return ; let smallest = Math . pow ( 10 , d - 1 ) ; let largest = Math . pow ( 10 , d ) - 1 ; for ( let i = smallest ; i <= largest ; i ++ ) { if ( isPalindrome ( i ) ) document . write ( i + " " ) ; } } let d = 2 ; printPalindromes ( d ) ;