# C Program to Check Number is Equal to its Reverse

« Previous Program Next Program »

In this article, you will learn about checking whether the given number by user (at run-time) is equal to its reverse or not.

## Check Number is Equal to its Reverse in C

To check whether the reverse of a number is equal to its original or not in C programming, you have to ask from user to enter the number, then reverse that number. Check whether the reverse value is equal to the original value or not as shown in the program given below:

```#include<stdio.h>
#include<conio.h>
int main()
{
int num, orig, rev=0, rem;
printf("Enter a Number: ");
scanf("%d", &num);
orig = num;
while(num>0)
{
rem = num%10;
rev = (rev*10)+rem;
num = num/10;
}
if(orig==rev)
printf("\nThis number is equal to its Reverse");
else
printf("\nThis number is not equal to its Reverse");
getch();
return 0;
}```

This program was compiled and executed using Code::Blocks IDE. Here is the first snapshot of a sample run:

Now supply any number say 565, and press ENTER to see the output as shown in the snapshot given below:

As the reverse of 565 is the number itself, so you will see the message as given in previous output.

Before reversing the given number, initialize its value to any variable say orig. So that, after reversing the number, compare it with orig. Here is another sample run. Let's suppose, user enters 422 as input this time:

Because, 422 is not equal to its reverse, so you will see the message as shown in previous snapshot. The reverse of 422 will be 224. And these two numbers is not equal to each other.

#### Same Program in Other Languages

C Online Test

« Previous Program Next Program »