= Solution
Normalize a copy, skip high-order zero blocks, print the highest block ordinarily, and pad all remaining blocks:
``
procedure OutNum(n: number)
z := CopyNum(n)
Normal(z)
i := len(z)-1
while i > 0 and z[i] = 0 do
i := i-1
Out.Int(z[i])
i := i-1
while i >= 0 do
place := base div 10
while place > 0 do
digit := (z[i] div place) mod 10
Out.Char(character('0' + digit))
place := place div 10
i := i-1
``
Here `Out.Int` writes an ordinary unpadded decimal integer, and `character('0' + digit)` denotes its decimal digit character. Since $base=10^k$ for $k\geq1$, the inner loop writes exactly $k$ characters per lower block. This <power-of-ten digit-block formatting> retains internal zeros: base-$1000$ digits $[4,0,12]$ print as \b[`12000004`], not `1204`. An all-zero array prints exactly \b[`0`]. The caller's original array is preserved.
Back to article page