C++ Program to Check Number is Equal to its Reverse

Here you will learn and get code on checking whether the input number is equal to its reverse or not in C++.

To check that the original number is equal to its reverse or not in C++ programming, you have to ask from user to enter the number first. Then initialize its value (number entered by user) to a variable say orig and then reverse that number (entered by user). Finally compares its reverse with orig to check whether reverse is equal to original or not as shown in the following program:

using namespace std;
int main()
    int num, orig, rev=0, rem;
    cout<<"Enter the Number: ";
    orig = num;
        rem = num%10;
        rev = (rev*10)+rem;
        num = num/10;
        cout<<"\nThis Number is equal to its Reverse";
        cout<<"\nThis Number is not equal to its Reverse";
    return 0;

This program was build and run under Code::Blocks IDE. Here is its sample run:

C++ program check reverse original

Now supply any input as input say 1234 to check whether its reverse is equal to the number itself or not as shown in the output given below:

reverse original program c

Here is another sample run with user input as 12321:

check number is equal to its reverse c++

Note - Make sure to initialize the input value to a variable say orig before reversing the number.

As you can see from above program, we have reversed the number and then compares it with original (value stored in orig).

Same Program in Other Languages

C++ Online Test

« Previous Program Next Program »