Pages

jueves, 24 de enero de 2013

Calcular el número mayor y menor de una lista de 100 números Codigo Fuente en Visual Basic

Problema
Hacer un programa o algoritmo de una lista de 100 números determinar simultáneamente el máximo y mínimo número.

Codigo Fuente en Visual Basic
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles Button1.Click
        Dim Num(100) As Integer
        Dim ale As Integer = 0
        Dim may As Integer = -10000
        Dim men As Integer = 10000
        Dim cad As String = ""
        For i As Integer = 0 To 100
            Randomize()
            ale = CInt(Int((1000 * Rnd()) + 1))
            Num(i) = ale
            cad = cad + " " + Trim(ale)
        Next i
        TextBox1.Text = cad
        For j As Integer = 0 To 100
            If (Num(j) > may) Then
                may = Num(j)
            End If
        Next j
        For x As Integer = 0 To 100
            If (Num(x) < men) Then
                men = Num(x)
            End If
        Next x
        TextBox2.Text = "El mayor es: " + Trim(may) &
            vbCrLf & " el menor es:" + Trim(men)
    End Sub
End Class

0 comentarios:

Publicar un comentario en la entrada