Home » NO IDEA » Reverse the given number

Reverse the given number

Blog Stats

  • 13,912 hits
January 2013
M T W T F S S
« Dec   Mar »
 123456
78910111213
14151617181920
21222324252627
28293031  

If the given number  is 152 the reversed number of it is 251

// Reverse the given digits
#include<stdio.h>
int main()
{
int num,r,rev;
rev=0;
printf("\n Enter the Number to be reversed");
scanf("%d",&num);
while(num>0)
{
r=num%10;
rev=rev*10+r;
num/=10;
}
printf("\n The reversed number is %d",rev);
return 0;
}
Advertisements

1 Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: