1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
// for: int putchar(int);

unsigned long long n = 0x123456789ABCDEF;

char buf[20];

int
main()
{
    // local variables are used as registers (the compiler will actually use
    // registers here if you compiler with -O1)
    unsigned long long val;
    char digit;
    char *p;

    // fetch variable n into val
    val = n;

    // p point to begin of buf array
    p = buf;
    do {
        digit = val % 10 + '0';
        val /= 10;

        // store ASCII value of digit at *p then increment pointer
        *(p++) = digit;
    } while (val != 0);

    // print stored characters
    for (; p != buf; putchar(*--p)) {
    }

    // print extra newline (not needed for quiz)
    putchar('\n');
}