Reverse of a number using c

This artical explains how can reverse a number using c programming


Category: C Programming Tags: C Programming, C++ Programming


Lets see how to reverse a number in c

see this code shown below:
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>

main()
{
int num,d,r,rev;
clrscr(); //it is in conio.h library
printf("Enter any number between 9 and 100\n");
scanf("%d", &num);
if(num<9 || num>100)
{
printf("wrong input\n");
getch(); //it is in conio.h library
exit(0); // it is in stdlib.h librery
}
r=num%10; // reminder
d=num/10; // the leftmost digit
rev=r*10+d; // reverse of the number
printf("reverse number is %d \n", rev);
getch();
}
Output:-
Enter any number between 9 and 100
75
reverse number is 57

Explanation:-
exit(0) is used to terminate the program if user enters the wrong number
if he enters 75 then:
r = num%10        =>  r = 75%10 = 5
d = num/10         =>  d = 75/10 = 7
rev = r*10+d       =>  rev = 5*10+7 = 57


Like 0 People
Published on 21 May 2013
Nikhil Joshi

Nikhil Joshi
Ceo & Founder at Dotnetlovers
Atricles: 132
Questions: 9
Given Best Solutions: 9 *

Comments:

Nikhil Joshi
like if u find it good :)
Like 3 People on 23 May 2013
rajesh gupta
nice article .. thank you
Like 1 Person on 23 May 2013

You are not loggedin, please login or signup to add comments:

Existing User

Login via:

New User



x