• Lenguaje

    Visual Basic .Net

  • Descripción

    Pide al usuario 10 nombres, los guarda en un arreglo, ordena el arreglo en orden alfabético con el método de la burbuja y muestra el arreglo ordenado.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Module Nombres

    Sub Main()
        Dim nombres(9), nombre As String
        Dim i, j As Integer
        For i = 0 To nombres.Length - 1
            Console.Write("Ingrese el nombre " & (i+1) & ": ")
            nombres(i) = Console.ReadLine()
        Next
        For i = 1 To nombres.Length - 1
            For j = 0 To nombres.Length - i - 1
                If nombres(j).CompareTo(nombres(j+1)) > 0 Then
                    nombre = nombres(j)
                    nombres(j) = nombres(j+1)
                    nombres(j+1) = nombre
                End If
            Next
        Next
        Console.WriteLine(vbCrLf & "Nombres ordenados:" & vbCrLf)
        For i = 0 To nombres.Length - 1
            Console.WriteLine("Nombre " & (i+1) & ": " & nombres(i))
        Next
        Console.WriteLine()
        Shell ("cmd /c pause", AppWinStyle.NormalFocus, True)
    End Sub

End Module