Introduction :
Reversing a number is a common problem that can be solved by programming. It can be useful in a variety of applications such as cryptography, data analysis and algorithm design. In this article, I shall discuss with you how to reverse a given number using simple mathematical calculations. Here, you shall learn how to reverse a given number in C programming language.
What is reverse number :
Rearranging the digits of any number in the opposite order is called reversing number. For example, after reversing the number 5483 is become 3845. The basic idea for reversing a number is to extract each digit from the number and create a new number in reverse order. Here, you see the last digit of the number becomes the first, the second digit becomes the second from last and so on.
About the program :
This is a simple program that takes an input (integer) from the user and display the reversed number on the console screen. First, it asks you to enter a number (integer). Then, it reverses the number and prints the result in the console.
Explanation of the program :
First, include the standard input output library (stdio.h) in the program. Then, declare integer variables (number, reverse_number, remainder and copy_number) in the main() function. Now, ask the user to enter an integer number using printf() function. Using scanf() function, store the number in “number” variable. After that, copy the original value of “number” variable in “copy_number” variable for later use.
To reverse a number, you have to use loops and mathematical operations. To implement this logic in C language, you can use the modulo operator (%) to extract the last digit of the number and the division operator (/) to remove the last digit from the number. You can repeat this process in a loop until the number becomes zero, which means that you have extracted all the digits.
Here, I run a while loop until number becomes zero (0). In the while loop, calculate the reverse number using the modulo (%) and division (/) operator. Finally, display the reverse number using printf() function.
How run the program :
If you want to run the program on your PC, you have to install Visual Studio Code (VS Code). To run the C program for reversing a number in VS Code, first open it and create a new C file like “reverse_number.c”. Then, copy the below code and paste in the file. Now, save the file and run it.
Source code of the program :
The following code is the source code of reversing a given number in C programming language.
/* Developd by Puskar Jasu*/
#include <stdio.h>
int main()
{
int number, reverse_number = 0, remainder, copy_number;
printf("Enter an integer for reverse number\n");
scanf("%d", &number);
copy_number = number;
while (number != 0)
{
remainder = number % 10;
reverse_number = reverse_number * 10 + remainder;
number /= 10;
}
printf("After reverse %d number is become %d\n", copy_number, reverse_number);
return 0;
}
Output of the program :
After Successfully run the code in VS Code on your pc, you can see the following output like below image.

Conclusion :
Reversing a number in C programming language is a simple process where I use loops and mathematical operations. With the above step by step guide, you can easily reverse any number using the C programming language. At last, you have learned how to reverse a given number in C programming language. Thank you for visiting my site.