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

Input number: 1234

Output reverse: 4321

Happy coding ;)

**Example:**Input number: 1234

Output reverse: 4321

### Required knowledge

Basic C programming, For loop### Logic to find reverse

Logic of reversing of any number is pretty simple if you know how to find last digit of any number. The process of reversing involves four basic steps:- Multiply the rev variable by 10.

- Find the last digit of the given number.
- Add the last digit just found to rev.
- Divide the original number by 10 to eliminate the last digit, which is not needed anymore.

### Program to find reverse

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

**Note:**Don't forget to learn the recursive approach of finding reverse of any number.

Output

Enter any number to find reverse: 1234

Reverse = 4321

Reverse = 4321

Happy coding ;)

### You may also like

- Loop programming exercises index.
- C program to check whether a number is palindrome or not.
- C program to check whether a number is divisible by 5 and 11 or not.
- C program to find the sum of first and last digits of a number.
- C program to print table of any given number.
- C program to print all even numbers between 1 to n.
- C program to print sum of all odd numbers between 1 to n.
- C program to print all natural numbers from 1 to n.
- C program to print all alphabets from a to z.
- C program to print fibonacci series up to n terms.
- C program to print pascal triangle.
- C program to convert binary to octal number system.
- C program to convert hexadecimal to decimal number system.

< code >< pre > -- Your source code -- < /pre >< /code > (Remove spaces from pre and code tags).