8 | *
7 | *
6 | *
5 | *
4 | * *
3 |* * * * * *
2 |* * * * *** ** * *
1 |* * *** ****** **** * *
+---------------------------
012345678901234567890123456
11111111112222222
how would you print numbers from the least significant digits to the most significant digits (like the numbers shown on the x-axis)? 开发者_JS百科Thank you
Put the number in a temp.
The next digit to print is temp % 10
Divide 10 into temp.
If temp isn't 0, repeat the prior two steps.
Printing from the LSD to the MSD is actually simpler then the other way around. The reason why is that the remainder/division technique to extract the digits of a number produces the least-significant before the most-significant.
if (i == 0)
output_digit(0)
else
while (i != 0)
output_digit(i % base)
i = i / base
This will output digits in the order you want. For base 10, the number 123 will first output 3, then 2 and finally 1.
精彩评论