Write a C program to enter any number from user and find reverse of the given number using for loop. How to find reverse of any number in C programming using loops. Logic to find reverse of any number in C program.

**Example**

**Input**

Input number: 1234

**Output**

Reverse of 1234 = 4321

## Required knowledge

## Logic to find reverse

I have divided the logic to find reverse of any number in four simple steps.

- Extract the last digit of the given number by performing modulo operation.
- Increase the place value of reverse. For that multiply reverse variable by 10.
- Add the last digit computed above, with reverse.
- Remove the last digit by dividing the number by 10. As it is not needed anymore.

Let us implement the logic in a C program.

## Program to find reverse of any number

/** * C program to find reverse of any number */ #include <stdio.h> int main() { int num, reverse = 0; /* Read the number from user */ printf("Enter any number to find reverse: "); scanf("%d", &num); /* Repeat the till num becomes 0 */ while(num != 0) { /* Multiple rev by 10 and adds the last digit to it*/ reverse = (reverse * 10) + (num % 10); /* Remove last digit from num */ num = num / 10; } printf("Reverse = %d", reverse); return 0; }

**Note:** Take your skills to next level. Learn this program using recursive approach.

Output

Enter any number to find reverse: 1234 Reverse = 4321

Happy coding ;)

### You may also like

- C program to count number of digits in any number.
- C program to find sum of first and last digit of any number.
- C program to swap first and last digit of any number.
- C program to print multiplication table of any number.
- C program to find frequency of each digit in given number.
- C program to print number in words.

< pre>< code >----Your Source Code---- < / code > < / pre > (Remove spaces from pre and code tags)