C++ Program to check a number is a palindrome or not using the function


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


123 After Reverse => 321

101 After Reverse => 101


Example: How to check a number is a palindrome or not using the function in C++

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

int checkNumber(int n) {

    int r, rev = 0;

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

int main() {

    int n, num;

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

    num = checkNumber(n);
    if (num == n) {
        cout << "\nThe Number is Palindrome :" << n;
    } else {
        cout << "\nThe Number is Not Palindrome :" << n;
    }

    return 0;
}

Output:

Enter a Number :121
The Number is Palindrome :121