Determinar un algoritmo que permita convertir un número arábigo comprendido entre 1 y 999 a números romanos
Solución
- Entrada: 697
- Salida: DCXCVII
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim N, u, d, c As Integer Dim Unidad() As String = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"} Dim Decena() As String = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"} Dim Centena() As String = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"} N = TextBox1.Text u = N Mod 10 d = Math.Floor(N / 10) Mod 10 c = Math.Floor(N / 100) If (N >= 100) Then TextBox2.Text = Centena(c) + Decena(d) + Unidad(u) Else If (N >= 10) Then TextBox2.Text = Decena(d) + Unidad(u) Else TextBox2.Text = Unidad(N) End If End If End Sub End Class
1 comentarios:
Excelente, muchas gracias.
Publicar un comentario