To check a number is palindrome or not without using any extra space | C ++ program to find number is palindrome or not without using any extra space ; Function to check if given number is palindrome or not without using the extra space ; Find the appropriate divisor to extract the leading digit ; If first and last digit not same return false ; Removing the leading and trailing digit from number ; Reducing divisor by a factor of 2 as 2 digits are dropped ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isPalindrome ( int ) ; bool isPalindrome ( int n ) { int divisor = 1 ; while ( n / divisor >= 10 ) divisor *= 10 ; while ( n != 0 ) { int leading = n / divisor ; int trailing = n % 10 ; if ( leading != trailing ) return false ; n = ( n % divisor ) / 10 ; divisor = divisor / 100 ; } return true ; } int main ( ) { isPalindrome ( 1001 ) ? cout << " Yes , ▁ it ▁ is ▁ Palindrome " : cout << " No , ▁ not ▁ Palindrome " ; return 0 ; }