Task

Create a function taking a positive integer as its parameter and returning a string containing the Roman numeral representation of that integer. Modern Roman numerals are written by expressing each digit separately, starting with the left most digit and skipping any digit with a value of zero.



In Roman numerals:

 1990 is rendered: 1000=M, 900=CM, 90=XC; resulting in MCMXC
 2008 is written as 2000=MM, 8=VIII; or MMVIII
 1666 uses each Roman symbol in descending order: MDCLXVI


BEGIN
 
    TEXT PROCEDURE TOROMAN(N); INTEGER N;
    BEGIN
        PROCEDURE P(WEIGHT,LIT); INTEGER WEIGHT; TEXT LIT;
        BEGIN
            WHILE N >= WEIGHT DO
            BEGIN
                T :- T & LIT;
                N := N - WEIGHT;
            END WHILE;
        END P;
        TEXT T; T :- NOTEXT;
        P( 1000, "M"  );
        P(  900, "CM" );
        P(  500, "D"  );
        P(  400, "CD" );
        P(  100, "C"  );
        P(   90, "XC" );
        P(   50, "L"  );
        P(   40, "XL" );
        P(   10, "X"  );
        P(    9, "IX" );
        P(    5, "V"  );
        P(    4, "IV" );
        P(    1, "I"  );
        TOROMAN :- T;
    END TOROMAN;
 
    INTEGER Y;
    FOR Y := 1990, 2008, 1666 DO
    BEGIN
        OUTTEXT("YEAR ");
        OUTINT(Y, 4);
        OUTTEXT(" => ");
        OUTTEXT(TOROMAN(Y));
        OUTIMAGE;
    END FOR;
 
END PROGRAM;
 