Jump to content

Roman numerals/Encode: Difference between revisions

m (Emacs Lisp: Improve formatting)
Line 1,054:
 
=={{header|BASIC}}==
==={{header|ASIC}}===
{{trans|DWScript}}
<lang basic>
REM Roman numerals/Encode
DIM Weights(12)
DIM Symbols$(12)
DATA 1000, "M", 900, "CM", 500, "D", 400, "CD", 100, "C", 90, "XC", 50, "L"
DATA 40, "XL", 10, "X", 9, "IX", 5, "V", 4, "IV", 1, "I"
REM 3888 or MMMDCCCLXXXVIII (15 chars) is the longest string properly encoded
REM with these symbols.
FOR J = 0 TO 12
READ Weights(J)
READ Symbols$(J)
NEXT J
 
AValue = 1990
GOSUB ToRoman:
PRINT Roman$
REM MCMXC
AValue = 2022
GOSUB ToRoman:
PRINT Roman$
REM MMXXII
AValue = 3888
GOSUB ToRoman:
PRINT Roman$
REM MMMDCCCLXXXVIII
END
 
ToRoman:
REM Result: Roman$
Roman$ = ""
I = 0
Loop:
IF (I > 12 THEN ExitToRoman:
IF AValue <= 0 THEN ExitToRoman:
WHILE AValue >= Weights(I)
Roman$ = Roman$ + Symbols$(I)
AValue = AValue - Weights(I)
WEND
I = I + 1
GOTO Loop:
ExitToRoman:
RETURN
</lang>
 
==={{header|Commodore BASIC}}===
{{works with|Commodore BASIC|7.0}}
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.