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
2 comentarios:
No seria mas eficiente si el la comparación del menor la hicieras dentro del mismo primer For.
For j As Integer = 0 To 100
If (Num(j) > may) Then
may = Num(j)
End If
If (Num(j) < men) Then
men = Num(j)
End If
Next j
el Num(j) es un vector?
Publicar un comentario