Check if the number is Palindrome - C++ Program

Q. Write a C++ program to check whether the entered number is palindrome or not.

Answer:

Palindrome number is a number, same after reverse. For example: 131, 454, 1221 are the palindrome numbers. Following program shows that whether the entered number is palindrome or not.

#include<iostream>
using namespace std;
int main()
{
        int num, rem, orig, rev=0;

        cout<<"\n Enter Number : ";
        cin>>num;

        orig=num;
        while(num!=0)
        {
                rem=num%10;
                rev=rev*10 + rem;
                num=num/10;
        }

        if(rev==orig)  // check if original number is equal to its reverse
        {
                cout<<"\n Number is Palindrome";
        }
        else
        {
                cout<<"\n Number is Not Palindrome";
        }
        return 0;
}


Output:

palindrome