Floyd's triangle   lists the natural numbers in a right triangle aligned to the left where

 the first row is   1     (unity)
 successive rows start towards the left with the next number followed by successive naturals listing one more number than the line above.


The first few lines of a Floyd triangle looks like this:

 1
 2  3
 4  5  6
 7  8  9 10
11 12 13 14 15



Task

 Write a program to generate and display here the first   n   lines of a Floyd triangle. 
(Use   n=5   and   n=14   rows).
 Ensure that when displayed in a mono-space font, the numbers line up in vertical columns as shown and that only one space separates numbers of the last row.


include "cowgol.coh";
 
sub width(n: uint16): (w: uint8) is
    w := 1;
    while n >= 10 loop
        n := n / 10;
        w := w + 1;
    end loop;
end sub;
 
sub print_fixed(n: uint16, w: uint8) is
    w := w - width(n);
    while w > 0 loop
        print_char(' ');
        w := w - 1;
    end loop;
    print_i16(n);
end sub;
 
sub floyd(rows: uint16) is
    var maxno := rows * (rows+1)/2;
    var num: uint16 := 1;
    var row: uint16 := 1;
    while row <= rows loop
        var col: uint16 := 1;
        while col <= row loop
            print_fixed(num, 1 + width(maxno - rows + col));
            num := num + 1;
            col := col + 1;
        end loop;
        print_nl();
        row := row + 1;
    end loop;
end sub;
 
floyd(5);
print_nl();
floyd(14);