C++ Program to check a number is palindrome or not


In this program, You will learn how to check a number is palindrome or not in C++.


Some list of palindrome number is : 11, 22, 33, 101, 222.

Example: How to check a number is palindrome or not in C++.

#include<iostream>
using namespace std;

int main() {

    int x, t;
    int r, rev = 0;

    cout << "Enter a number:";
    cin>>x;

    t = x;
    while (x > 0) {
        r = x % 10;
        rev = rev * 10 + r;
        x = x / 10;
    }

    if (t == rev) {
        cout << "Number is palindrome:" << rev;
    } else {
        cout << "Number is not palindrome:" << rev;
    }

    return 0;
}

Output:

Enter a number:121
Number is palindrome:121