FoxPro/Visual FoxPro - Números romanos convertir

 
Vista:
sin imagen de perfil

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
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Números romanos convertir

Publicado por José Duarte (2 intervenciones) el 28/07/2016 13:13:26
Mejor imposible Gracias
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar