# C Program to reverse a number

In this program, we will take a number from the user and will write a sequence of codes to find the reverse of a number. C Program to reverse a number is one of the most important programs from placements point fo view.

If you have just started learning C Programming, I will suggest you go through – Introduction of C Language. and Structure of C Program.

### 1. First Method – C Program to reverse a number

In this method, we will take a number from the user using **Scanf() **function and will apply our code to calculate the reverse of the number.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include<stdio.h> #include<conio.h> int main() { int number; printf("PLease enter the number"); scanf("%d",&number); int remainder,sum=0; while(number>0) { remainder=number%10; sum=sum*10+remainder; number= number/10; } printf("The reverse of the number is"); printf("%d",sum); return 0; } |

**Output: **Please enter the number 789 The reverse of the number is 987

### Second Method –

In this method, we will make a function which will take the number from the user and will give the integer reverse number. This approach is better and should be used.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include<stdio.h> #include<conio.h> int reverse_number(int value); int main() { int number; printf("PLease enter the number"); scanf("%d",&number); int reverse= revrese_number(number); printf("The reverse of the number is"); printf("%d",reverse); return 0; } int reverse_number(int value) { int remainder,sum=0; while(number>0) { remainder=number%10; sum=sum*10+remainder; number= number/10; } return sum; } |

**Output: **Please enter the number 789 The reverse of the number is 987

This approach is used by experienced programmers and for more clear code. The extension of this program is to find whether the number is palindromic or not?.

You can also check the palindromic number at GeeksforGeeks.

**Is it important from placement point of view?**

Yes, this program is very important and is asked in many interviews too.

**Can we find a palindrome of a number using this method?**

Yes, the Palindrome number is an extension of this program.