Finding reverse of a number?

Hello i want some help.Below is a source code of a program which can find the reverse of a number.Please some one tell me the working of statements given inside while.How reverse is calculated?

#include<iostream.h>
#include<conio.h>

main()
{
clrscr();

int number;
int remainder;

cout<<"\n Enter the number = ";
cin>>number;

cout<<"\n The number with reverse digits is = ";

while(number>0)
{
remainder=number%10;

cout<<remainder;

number=number/10;
}

getch();
return 0;
}
Simple. Let number = 135;

Now first step, gets the last digit of a number by using remainder division with 10 (the modulus gives the remainder of division).
So that makes remainder = 5.
We output 5, then remove that digit from 135 by dividing by 10.

It repeats that, giving us the output of 531 on the same line.
The important part is the 10. Dividing by 10 always gives/removes the units column or the right most spot of a number depending on if you are dividing or getting the remainder.

135 / 10 = 13; 135 % 10 = 5;
13 / 10 = 1; 13 % 10 = 3;
1 /10 = 0; 1 % 10 = 1;
Thanks dear you help lot...............
Topic archived. No new replies allowed.