-2
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)? Thank you

madth3
  • 7,275
  • 12
  • 50
  • 74
user133466
  • 3,391
  • 18
  • 63
  • 92

2 Answers2

2

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.

Drew Dormann
  • 59,987
  • 13
  • 123
  • 180
0

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.

R Samuel Klatchko
  • 74,869
  • 16
  • 134
  • 187