# Reverse of a Given Number

## Reverse of a Given Number

A number can be inversed using a C program. For instance, if the user inputs number 123456, it will be inverted to 654321. The C program uses a simple while loop for this method. The algorithm mentioned below will help us know how the number can be inverted or inversed.

## Algorithm to Reverse a Number in C

Step 1. Start

Step 2. Enter the number

Step 3. Using while loop from the entered number to zero, take the mode of the number by 10 and store value in d.

Step 4. Multiply the result with 10, add d and store the number in a variable (reversed number)

Step 5. Store the result by dividing the number by 10.

Step 6. Print the reversed number.

Step 7. Stop

Read Also: Program for Armstrong numbers between two intervals

### C Program to Reverse a number in C

```//C Program to print reverse of a given number
#include
#include
void main()

{
long int number, reversed_n=0, d=0;
clrscr();
printf("Insert the number\n\n");
scanf("%ld",&number);
while(number>0)
{
d=number%10;
reversed_n=reversed_n*10+d;
number=number/10;
}
printf("%ld",reversed_n);
getch();
}

```

### Output

```Insert the number: 456789
987654
```