New Member FAQ
|
Forums
|
Earn Revenue
|
Distance Education
|
Help Topics
|
Admissions 2013
Login
Register
Articles
Practice Tests
Ask Experts
Question Papers
Jobs
Universities
Colleges
Courses
Schools
Gift Shop
|
Bookmarks
|
Reviews
|
Learn English
|
Social Hub
|
Training
|
New Posts
|
My India
|
Members
|
Polls
|
Active Members
Today
mahi patel
(200)
R Pramod
(191)
Stalin.J
(135)
Last 7 Days
R Pramod
(997)
K Mohan
(723)
yash
(534)
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!
Tweet
Responses to "Reverse a number using C programme"
Author:
Raghav
21 Aug 2008
Member 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:
Notify me by email when others post comments to this article.
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
A C Project to print marklist
C programme to print 1000 amstrong numbers
Palimdrom of a string in C
A programme to find number of characters,number of lines and number of words in C
C programme to find simple and compound interest
C programme to print Prime Numbers
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
Awards & Gifts
Online Members
Jebaprincy
Venkiteswaran.
c p yadav
Nagaranjith Nagarajan
SONALI MESHRAM
Indira Bishui
Angelo
Kokil Kumar Sarma
Reema
Ankit Sinha
More...