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


proc    Rom(N, A, B, C);        \Display 1..9 in Roman numerals
int     N, A, B, C, I;
[case N of
9:      [ChOut(0, C);  ChOut(0, A)];                            \XI
8,7,6,5:[ChOut(0, B);  for I:= 1 to rem(N/5) do ChOut(0, C)];   \V
4:      [ChOut(0, C);  ChOut(0, B)]                             \IV
other   for I:= 1 to N do ChOut(0, C);                          \I
];
 
proc    Roman(N);               \Display N in Roman numerals
int     N, Q;
[Q:= N/1000;  N:= rem(0);       \0..3999
Rom(Q, ^?, ^?, ^M);
Q:= N/100;  N:= rem(0);         \0..999
Rom(Q, ^M, ^D, ^C);
Q:= N/10;  N:= rem(0);          \0..99
Rom(Q, ^C, ^L, ^X);
Rom(N, ^X, ^V, ^I);             \0..9
];
 
int     Tbl, I;
[Tbl:= [1990, 2008, 1666, 0, 1, 3999, 2020, 1234];
for I:= 0 to 7 do
        [IntOut(0, Tbl(I));  Text(0, ". ");  Roman(Tbl(I));  CrLf(0)];
]