C++ Program to check a number is palindrome or not using class and object


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


Some list of palindrome number's: 11, 101, 121, 19391


Example: How to check a number is palindrome or not using class and object in C++

Run it Now
#include<iostream>
using namespace std;

class Test {
public:

    int reverse(int x) {
        int r, rev = 0;

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

int main() {

    int x, rev;

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

    Test obj;
    rev = obj.reverse(x);

    if (rev == x) {
        cout << "\nNumber is Palindrome :" << x;
    } else {
        cout << "\nNumber is Not Palindrome :" << x;
    }

    return 0;
}

Output:

Enter a Number :151
Number is Palindrome :151