Find the Kth smallest odd length palindrome number | C ++ program for the above approach ; Function to find the Kth smallest odd length palindrome ; Store the original number K ; Removing the last digit of K ; Generate the palindrome by appending the reverse of K except last digit to itself ; Find the remainder ; Add the digit to palin ; Divide K by 10 ; Return the resultant palindromic number formed ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int oddLengthPalindrome ( int k ) { int palin = k ; k = k / 10 ; while ( k > 0 ) { int rev = k % 10 ; palin = ( palin * 10 ) + rev ; k = k / 10 ; } return palin ; } int main ( ) { int k = 504 ; cout << oddLengthPalindrome ( k ) ; }