C++ Program to check Whether a Number is Palindrome or Not

  • Write a C++ program to check whether a number is palindrome or not.

C++ program to check palindrome number

#include <iostream>

using namespace std;
 
int main(){
    int inputNumber, reverseNumber = 0, rightDigit, temp;
    cout << "Enter a number\n";
    cin >> inputNumber;
    
    temp = inputNumber;
    // reverse inputNumber and store it in reverseNumber
    while(temp != 0){
        rightDigit = temp % 10;
        reverseNumber = (reverseNumber * 10) + rightDigit;
        temp = temp/10;
    }
    // If input Number and reverse Number are same 
 // then palindrome othrwise not
    if(reverseNumber == inputNumber){
        cout << inputNumber << " is Palindrome Number";
    } else {
        cout << inputNumber << " is not a Palindrome Number";
    }
     
    return 0;
}
Output
Enter a number
1234321
1234321 is Palindrome Number
Enter a number
123456
123456 is not a Palindrome Number