g++ problem!?
Posted: Wed Oct 15, 2003 2:05 pm
I want to extract the last two non-zero digits from an int n, using the following code:
[cpp]while (n%10 == 0)
n /= 10;
n %= 100;[/cpp]
if i input 26300, the change of value of n is as expected
n=26300
n=2630
n=263
n=63
but it doesn't run as expected when the value of n is 10...
[cpp]while (n%10 == 0)
n /= 10;
n %= 100;[/cpp]
if i input 26300, the change of value of n is as expected
n=26300
n=2630
n=263
n=63
but it doesn't run as expected when the value of n is 10...
what actually is the radical of this problem?[cpp]n%10 == 0 [/cpp]-> ture
[cpp]n /= 10 [/cpp]-> n=1
[cpp]n%10 == 0 [/cpp]-> what will be executed : 0%10 == 0 !!!!!! but I expect 1%10 == 0