
Números romanos convertir
Publicado por Guillermo Arias (294 intervenciones) el 28/11/2012 02:47:14
Acá les dejo una rutina para convertir números arábigos en romanos. suerte
function roman
LPARAMETERS InputValue
RomanValue =''
if InputValue > 3999 OR InputValue < 1
return "N/A"
endif
RomanValue = ""
DO While InputValue > 999
RomanValue = RomanValue + "M" && Concatenate the letters to the right side
InputValue = InputValue - 1000 && Reduce the amount left in InputValue
ENDDO
If InputValue > 899
RomanValue = RomanValue + "CM" && Concatenate letters to the right side
InputValue = InputValue - 900
ENDIF
If InputValue > 499
RomanValue = RomanValue + "D"
InputValue = InputValue - 500
ENDIF
If InputValue > 399
RomanValue = RomanValue + "CD"
InputValue = InputValue - 400
endif
DO While InputValue > 99
RomanValue = RomanValue + "C"
InputValue = InputValue - 100
enddo
If InputValue > 89
RomanValue = RomanValue + "XC"
InputValue = InputValue - 90
endif
If InputValue > 49
RomanValue = RomanValue + "L"
InputValue = InputValue - 50
endif
If InputValue > 39
RomanValue = RomanValue + "XL"
InputValue = InputValue - 40
endif
DO While InputValue > 9
RomanValue = RomanValue + "X"
InputValue = InputValue - 10
enddo
If InputValue > 8
RomanValue = RomanValue + "IX"
InputValue = InputValue - 9
endif
If InputValue > 4
RomanValue = RomanValue + "V"
InputValue = InputValue - 5
endif
If InputValue > 3
RomanValue = RomanValue + "IV"
InputValue = InputValue - 4
endif
DO While InputValue > 0
RomanValue = RomanValue + "I"
InputValue = InputValue - 1
enddo
RETURN RomanValue
ENDFUNC
function roman
LPARAMETERS InputValue
RomanValue =''
if InputValue > 3999 OR InputValue < 1
return "N/A"
endif
RomanValue = ""
DO While InputValue > 999
RomanValue = RomanValue + "M" && Concatenate the letters to the right side
InputValue = InputValue - 1000 && Reduce the amount left in InputValue
ENDDO
If InputValue > 899
RomanValue = RomanValue + "CM" && Concatenate letters to the right side
InputValue = InputValue - 900
ENDIF
If InputValue > 499
RomanValue = RomanValue + "D"
InputValue = InputValue - 500
ENDIF
If InputValue > 399
RomanValue = RomanValue + "CD"
InputValue = InputValue - 400
endif
DO While InputValue > 99
RomanValue = RomanValue + "C"
InputValue = InputValue - 100
enddo
If InputValue > 89
RomanValue = RomanValue + "XC"
InputValue = InputValue - 90
endif
If InputValue > 49
RomanValue = RomanValue + "L"
InputValue = InputValue - 50
endif
If InputValue > 39
RomanValue = RomanValue + "XL"
InputValue = InputValue - 40
endif
DO While InputValue > 9
RomanValue = RomanValue + "X"
InputValue = InputValue - 10
enddo
If InputValue > 8
RomanValue = RomanValue + "IX"
InputValue = InputValue - 9
endif
If InputValue > 4
RomanValue = RomanValue + "V"
InputValue = InputValue - 5
endif
If InputValue > 3
RomanValue = RomanValue + "IV"
InputValue = InputValue - 4
endif
DO While InputValue > 0
RomanValue = RomanValue + "I"
InputValue = InputValue - 1
enddo
RETURN RomanValue
ENDFUNC
Valora esta pregunta


0