# Can someone help me understand this plz?

This is a discussion on Can someone help me understand this plz? within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> int main(void) { int no,reverse=0,digit; scanf("%d",&no); for( ;no>0; ) { digit=no%10; reverse=reverse*10 + digit; no=no/10; } printf("%d",reverse); ...

1. ## Can someone help me understand this plz?

Code:
```#include <stdio.h>

int main(void)
{
int no,reverse=0,digit;

scanf("%d",&no);
for( ;no>0; )
{
digit=no%10;
reverse=reverse*10 + digit;
no=no/10;
}

printf("%d",reverse);

system("PAUSE");
return 0;
}```
I don tunderstand how the code inside the for loop gets you the reverse of the number entered. Please help.

2. Do you know what the % operator does?
Do you know what the / operator does?

12 % 10 is what?
That, * 10 is what?

Quzah.

3. Originally Posted by quzah
Do you know what the % operator does? yes
Do you know what the / operator does? yes
How about the * operator? yes

12 % 10 is what? 2
That, * 10 is what? 20

Quzah.
still unclear on it.

4. The mod 10, in a base 10 numbering system like ours, "peels off" the right most digit.

Then you assign that digit to reverse, and divide the number "no", by 10 to move the next (10's place digit), into the one's place, and you're ready to do it again.

Since adding is always done from the one's place to the higher places, you've now swapped the number's digits, around.