Active Members
Today
Last 7 Days
more...

Resources » Articles/Knowledge Sharing » Computer & Technology

# Reverse a number using C programme

 Posted Date: 20-Aug-2008 Category: Computer & Technology Author: sobha wilson Member Level: Gold Points: 1

#include
main()
{
int num;
void reverse(int num);//The function for reversing is decleared.
clrscr();
printf("enter number");
scanf("%d",&num);
reverse(num);//The function is called.
getch();
}

void reverse(int num)
{
int temp=0;
int rev=0;
temp=num;//The number is stored in to another variable.
while(temp!=0)//We are using that dupicate.
{
rev=rev*10+temp%10;//By using temp%10, we will get the last digit of the number.
temp/=10;//Then the number is get reduced by one.
}
printf("%d",rev);\\After the end of loop reverse of number will stored in rev.
}

Example

consider n=123
we are assigned that number in to 'temp'.
in the loop the condition is "temp!=0".
now temp=123.
the step temp%10 means take it's reminder it will be 3.
we decleared rev=0.
so 'rev=rev*10+temp%10' means 3. [rev*10=0].
Now rev=3.
the next step is temp/10. Now temp=12.
The codition of the loop is true so it will cotinue.
Now temp%10 = 2.
so 'rev=rev*10+temp%10' means 32. [rev*10=30].
It will continue.

Did you like this resource? Share it with your friends and show your love!

Responses to "Reverse a number using C programme"
Author: Raghav    21 Aug 2008Member Level: Gold   Points : 1
Shoba,
you could have given some explanation of what each part of the code does. That is the normal practice so that everyone who reads the code will understand it easily. Kindly give a brief description of the code and what each function does.

Raghav

Feedbacks

## Post Comment:

• Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
• No HTML formatting and links to other web sites are allowed.
• This is a strictly moderated site. Absolutely no spam allowed.
•  Name: Sign In to fill automatically. Email: (Will not be published, but required to validate comment) Type the numbers and letters shown on the left.

 Next Resource: Programme to print N prime numbers Previous Resource: C programme to print multiplication table Return to Resources Post New Resource Category: Computer & Technology

Post resources and earn money!

More Resources
 Popular Tags Tag posting guidelines Search Tags
Reverse a number using C programme  .

### Subscribe to Email

• Get Jobs by Email
• Forum posts by Email
• Articles by Email