C Program to reverse number and compare(with Algorithm)
C Language

C Program to reverse number and compare(with Algorithm)

In this C program, we will reverse a five-digit number inputted by the user and check whether the original and reversed numbers are equal or not.

We will first take input value by the user and reverse the inputted number. Then we will determine whether the original and reversed number is equal or not.

Table of contents:-

  1. Concept
  2. Algorithm
  3. Program
  4. Output
  5. Resource

Before writing this C program, let’s learn about the concept we are gonna use in our program.


After taking the values inputted by the user. We will reverse the number with the help of a while loop concept. Then after getting the reversed number, we use the if-else in c program to check whether the original and reverse number is equal or not.

The concepts of C programming you need to learn before writing the program are:-

  1. while loop
  2. If else

Kindly learn these basic topics before continuing and writing this C program.

2. Algorithm

Here’s the algorithm of writing C program to reverse number inputted by user.

  1. START
  2. Input num
  3. revnum = revnum * 10;
  4. revnum = num % 10 + revnum;
  5. num = num/10;
  6. until num!=0
  7. Write revnum
  8. check revnum is same as num or not
  9. STOP

Keep this algorithm in mind while writing this C program.

3. C program to Reverse Number

After going through the algorithm, write the C Program to get input from user and reverse it to compare with the inputted number. You can watch the video tutorial, or can understand the code given below then video.

void main()
int num, n, revnum=0;

printf("Enter a five digit number: ");
scanf("%d", &num);
n = num;
revnum = revnum * 10;

revnum = num % 10 + revnum;

num = num/10;
printf("Reversed Number of %d is %d\n",n, revnum);

if (n==revnum)
printf("Input Number %d & Reversed Number %d are equal", n, revnum);
printf("Input Number %d & Reversed Number %d are not equal", n, revnum);


4. Output

After writing the C Program to reverse number and compare, lets check the output. As we have inputted the value 12321. Let’s have a look at the Output.

C Program reverse Number Output Algorithm

5. Resource

You can use the following resources and files to learn and try coding on your own device.

  1. C Program File
  2. Raw Code

Read next: C Program to Convert Temperature Celsius to Fahrenheit

Disclaimer: We used GCC Compiler for compiling this program. We are using Pastebin for hosting the raw and C Program File, we are not affiliated with Pastebin. You can checkout their privacy policy page for more information on what and how they handle your data.

Similar Posts