C Program to reverse a given number using Recursion
Here is the C program to reverse a number:
#include
int main() {
int n, reverse = 0, remainder;
printf("Enter a number: ");
scanf("%d", &n);
while (n != 0) {
remainder = n % 10;
reverse = reverse * 10 + remainder;
n /= 10;
}
printf("Reversed number: %d\n", reverse);
return 0;
}
Output

This program works by first getting the number from the user. Then, it uses a loop to reverse the digits of the number. Finally, it prints the reversed number.
Here is a breakdown of how the program works:
- The
printf()
function is used to print the prompt “Enter a number: “. - The
scanf()
function is used to read the number from the user. - The
while
loop is used to reverse the digits of the number. In each iteration of the loop, the remainder ofn
when divided by 10 is calculated and stored in the variableremainder
. The value ofreverse
is then multiplied by 10 and the value ofremainder
is added to it. Finally, the value ofn
is divided by 10. - The
printf()
function is used to print the reversed number. - The
return 0
statement is used to indicate that the program has completed successfully.