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:-
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:-
Kindly learn these basic topics before continuing and writing this C program.
Here’s the algorithm of writing C program to reverse number inputted by user.
- Input num
- revnum = revnum * 10;
- revnum = num % 10 + revnum;
- num = num/10;
- until num!=0
- Write revnum
- check revnum is same as num or not
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.
int num, n, revnum=0;
printf("Enter a five digit number: ");
n = num;
revnum = revnum * 10;
revnum = num % 10 + revnum;
num = num/10;
printf("Reversed Number of %d is %d\n",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);
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.
You can use the following resources and files to learn and try coding on your own device.