# 11+ C Programs to Reverse a Number

This post contains a total of 11+ Hand-Picked C Programs to Reverse a Number with Source Codes. All the programs are made using C Programming Language.

You can use the source code of these programs for educational purpose with credits to the original owner.

### Related Posts

Click a Code to Copy it.

## 1. By Mahesh Khatri

Made by Mahesh Khatri. Program to reverse a input number. Enter your number in n = 385. ( Source )

`Reversed Number = 583`
``````#include <stdio.h>
int main() {
int n, reversedNumber = 0, rem;
n = 385;

while(n != 0) {
rem = n % 10;
reversedNumber = reversedNumber * 10 + rem;
n /= 10;
}
printf("Reversed Number = %d", reversedNumber);
return 0;
}``````

## 2. By Thanigai Velan

Made by Thanigai Velan. Simple C Program to reverse a number. ( Source )

```5757
The reverse of the number is 7575```
``````#include <stdio.h>
int main()
{
int r=0;
int n;
scanf("%d",&n);
while(n>0)
{
r=r*10;
r=r+n%10;
n=n/10;
}
printf("The reverse of the number is %d",r);
return 0;
}``````

## 3. By vaibhav

Made by vaibhav. Program to accept any number and print it in reverse using recursive function. ( Source )

```Enter an integer : 7345
reverse of integer is 5437```
``````#include <stdio.h>

int reverse(int);
int main ()
{
int n , rev;
scanf("%d",&n);
printf("Enter an integer : %d\n",n);
rev = reverse(n);
printf("reverse of integer is %d",rev);
return 0;
}
int reverse (int n)
{
static int new=0;
if(n == 0)
return new;
else {
new = ((new*10) + (n%10)) ;
reverse(n/10) ;
}
return new;
}``````

## 4. By AsterisK

Made by AsterisK. ( Source )

```enter an integer 1334
the reverse of the number you entered is: 4331```
``````#include <stdio.h>

int main() {
int a,b,cnt=0,n;
printf("enter an integer\n");
scanf("%d",&a);
n=a;
//this part counts how many digits are in the user input
while(a>0){
a = a/10;
++cnt;
}
//now the reverse part should be like this
printf("the reverse of the number you entered is: ");
while(cnt>0){
printf("%d", n%10);
n = n/10;
- cnt;
}

return 0;
}``````

## 5. By Lakshay kamat

Made by Lakshay kamat. Prints the reversed numbers of a number. ( Source )

```05
04
03
02
01
00```
``````#include <stdio.h>
int main(int argc, char const *argv[])
{
//Enter a Number

int c;
scanf("%d",&c);
int i=c;
do
{
printf("%02d\n",i);
i--;
} while (i>=0);
return 0;
}``````

## 6. By Mukund Kedia

Made by Mukund Kedia. ( Source )

```468
864
```
`````` #include<stdio.h>
void main()
{
int n,a,i;
int s=0;

scanf("%d ",&n);

for(i=1;n!=0;i++)
{
a=n%10;
n=n/10;

printf("%d",a);
}

}``````

## 7. By Wajeeh

Made by Wajeeh. ( Source )

```436
Enter an integer: Reversed Number = 634```
``````#include <stdio.h>
int main()
{
int n, reversedNumber = 0, remainder;

printf("Enter an integer: ");
scanf("%d", &n);

while(n != 0)
{
remainder = n%10;
reversedNumber = reversedNumber*10 + remainder;
n /= 10;
}

printf("Reversed Number = %d", reversedNumber);

return 0;
}``````

## 8. By Yamin Mansuri

Made by Yamin Mansuri. A basic c program to reverse a number. ( Source )

```Entered Number is : 362
Reverse Number is : 263```
``````#include <stdio.h>

int main() {

int num;
int lastdigit ;
int reverse ;

reverse = 0;

scanf("%d",&num);
printf("Entered Number is : %d \n",num);
while (num>0){
lastdigit = num % 10;

reverse = (reverse*10)+lastdigit;

num = num / 10;}

printf("Reverse Number is : %d",reverse);

return 0;
}``````

## 9. By Umair Ali

Made by Umair Ali. ( Source )

```Enter a no: 244
no = 442```
``````#include <stdio.h>

int main()
{
int n,x=0;
printf("Enter a no: ");
scanf("%d",&n);while(n!=0)
{
x=x*10+n%10;

n=n/10;
}
printf("\n no = %d",x);

}``````

## 10. By Ipang

Made by lpang. Program to Reverse a floating point number (double). ( Source )

```Before: 14125.000000
After: 0.521410```
``````#include <stdio.h>
#include <stdlib.h>
#include <string.h>

double fp_reverse( const double n )
{
static char s[ 310 ] = { 0 };

if( !n ) return n;
if( -1 == sprintf( s, "%lf", n ) ) // put <n> into string <s>
{
return 0.0; // sprintf() return -1 on error, exit function
}

for( size_t L = strlen( s ) - 1, H = ( L + 1 ) / 2, i = ( *s == '-' ? 1 : 0 ); i < H; i++ )
{
char cswap = *( s + i ); // swap char from each end to reverse the string <s>
*( s + i ) = *( s + L - i );
*( s + L - i ) = cswap;
}

return strtod( s, NULL ); // return <s> as double
}

int main()
{
while( 1 )
{
double n;

if( 1 != scanf( "%lf", &n ) ) break; // read error, exit loop
printf( "Before: %lf\n", n );
printf( "After: %lf\n\n", fp_reverse( n ) );
}
return 0;
}``````

## 11. By kyllen

Made by kyllen ( Source )

```Input:  255
Result: 552```
``````#include <stdio.h>

/**
* Reverses
* a number.
*/
long
reverse( long n )
{
long ret = 0;

while (n) // > 0
{
/**
* Pushes the digits
* to the left.
*/
ret *= 10;

/**
* last digit.
*/
ret += (n % 10);

/**
* Removes the
* last digit.
*/
n /= 10;
}

return ret;
}

/**
* Main function.
*/
int
main( int          argc
, char const * argv[]
)
{
long input = 538279;
long result = 0;

scanf("%ld", &input);

result = reverse(input);

printf("Input:  %ld\n", input);
printf("Result: %ld\n", result);

return 0;
}
``````

## 12. By Skyler

Made by Skyler. Reverse number and check it with old number. ( Source )

```Enter any 5 digit number:

The entered number is = 1414
The reversed number is = 41410
Entered number and reversed number are not equal```
``````#include <stdio.h>

int main()
{
int num,renum=0,a,n;

printf ("Enter any 5 digit number:\n");

scanf("%d",&num) ;

a=num%10; //5th
n=num/10;
renum=renum+a*10000;

a=n%10;
n=n/10;
renum=renum+a*1000; //4th

a=n%10;
n=n/10;
renum=renum+a*100;//3rd

a=n%10;
n=n/10;
renum=renum+a*10;//2nd

a=n%10;
renum=renum+a;

printf ("\nThe entered number is = %d\nThe reversed number is = %d",num,renum );

if(num==renum)

printf("\nEntered Number and reversed are equal.so its a Palindrome");

else

printf ("\nEntered number and reversed number are not equal");
return 0;
}``````