REM Demo implementing decimal to roman number decoder REM http://en.wikipedia.org/wiki/Roman_numerals REM REM Taken from the roman example of BaCon. REM PvE, August 2014 - GPL. DECLARE roman[13] = { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" } TYPE char* DECLARE decimal[13] = { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 } TYPE int INTEGER i, num STRING result IF argc != 2 THEN PRINT "Usage: roman <number>" NL END 1 ENDIF LET num = VAL(argv[1]) FOR i = 0 TO 12 WHILE num >= decimal[i] SET result = CONCAT(result, roman[i]) DECR num, decimal[i] WEND NEXT PRINT result NL
Return to M4BASIC