C++ Program to check a number is a 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++.

#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 << "Number is palindrome:" << x;
    } else {
        cout << "Number is not palindrome:" << x;
    }

    return 0;
}

Output:

Enter a number:121
Number is palindrome:121

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.