PROGRAM ArabicToRoman(Output);
    {----------------------------------------------------
        program 4.9 - Write a table of powers of 2 in
        Arabic numbers and Roman numerals.
    -----------------------------------------------------
        For remind:
               1: I           2: II     3: III      4: IV
               5: V           9: IX
              10: X
              50: L          90: XC
             100: C
             500: D         900: CM
            1000: M
    -----------------------------------------------------
        Notice again that each "branch" of an if
        statement consists of only one statement.
        Therefore, when more than one action is
        intended, a compound statement is necessary.
    -----------------------------------------------------}

    VAR
        Rem,    { reminder }
        Number: Integer;
BEGIN
    Number := 1;
    REPEAT
        Write(Output, Number, ' ');
        Rem := Number;
        WHILE Rem >= 1000 DO
        BEGIN
            Write(Output, 'M');
            Rem := Rem - 1000
        END;

        IF Rem >= 900 THEN
        BEGIN
            Write(Output, 'CM');
            Rem := Rem - 900
        END ELSE IF Rem >= 500 THEN
        BEGIN
            Write(Output, 'D');
            Rem := Rem - 500
        END ELSE IF Rem >= 400 THEN
        BEGIN
            Write(Output, 'CD');
            Rem := Rem - 400
        END;

        WHILE Rem >= 100 DO
        BEGIN
            Write(Output, 'C');
            Rem := Rem - 100
        END;

        IF Rem >= 90 THEN
        BEGIN
            Write(Output, 'XC');
            Rem := Rem - 90
        END ELSE IF Rem >= 50 THEN
        BEGIN
            Write(Output, 'L');
            Rem := Rem - 50
        END ELSE IF Rem >= 40 THEN
        BEGIN
            Write(Output, 'XL');
            Rem := Rem - 40
        END;

        WHILE Rem >= 10 DO
        BEGIN
            Write(Output, 'X');
            Rem := Rem - 10
        END;

        IF Rem = 9 THEN
        BEGIN
            Write(Output, 'IX');
            Rem := Rem - 9
        END ELSE IF Rem >= 5 THEN
        BEGIN
            Write(output, 'V');
            Rem := Rem - 5
        END ELSE IF Rem = 4 THEN
        BEGIN
            Write(Output, 'IV');
            Rem := Rem - 4
        END;

        WHILE Rem >= 1 DO
        BEGIN
            Write(Output, 'I');
            Rem := Rem - 1
        END;

        WriteLn(Output);
        Number := Number * 2
    UNTIL Number > 5000
END.
