5 de febrero de 2022

Números Arábigos a Romanos

? NUM2ROMANO(1980)

FUNCTION Num2Romano(tnNum)
  DIMENSION laNum(13),laRom(13)
  LOCAL lnI, lcRom

  laNum(1) = 1
  laNum(2) = 4
  laNum(3) = 5
  laNum(4) = 9
  laNum(5) = 10
  laNum(6) = 40
  laNum(7) = 50
  laNum(8) = 90
  laNum(9) = 100
  laNum(10) = 400
  laNum(11) = 500
  laNum(12) = 900
  laNum(13) = 1000

  laRom(1) = "I"
  laRom(2) = "IV"
  laRom(3) = "V"
  laRom(4) = "IX"
  laRom(5) = "X"
  laRom(6) = "XL"
  laRom(7) = "L"
  laRom(8) = "XC"
  laRom(9) = "C"
  laRom(10) = "CD"
  laRom(11) = "D"
  laRom(12) = "CM"
  laRom(13) = "M"

  lcRom = ""

  FOR lnI = 13 TO 1 STEP -1
    DO WHILE tnNum >= laNum(lnI)
      tnNum = tnNum - laNum(lnI)
      lcRom = lcRom + laRom(lnI)
    ENDDO
  ENDFOR
  RETURN lcRom
ENDFUNC