How to get the digits of a number without converting it to a string/ char array?

The following prints the digits in order of ascending significance (i.e. units, then tens, etc.):

do {
    int digit = n % 10;
    putchar('0' + digit);
    n /= 10;
} while (n > 0);

Leave a Comment