Find all palindrome numbers of given digits | C ++ implementation of the approach ; 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int reverse ( int num ) { int rev = 0 ; while ( num > 0 ) { rev = rev * 10 + num % 10 ; num = num / 10 ; } return rev ; } bool isPalindrome ( int num ) { if ( num == reverse ( num ) ) return true ; return false ; } void printPalindromes ( int d ) { if ( d <= 0 ) return ; int smallest = pow ( 10 , d - 1 ) ; int largest = pow ( 10 , d ) - 1 ; for ( int i = smallest ; i <= largest ; i ++ ) { if ( isPalindrome ( i ) ) cout << i << " ▁ " ; } } int main ( ) { int d = 2 ; printPalindromes ( d ) ; return 0 ; }