metodo burbuja
Publicado por smile (10 intervenciones) el 08/12/2005 02:24:54
Tengo que hacer un programa con arreglos dinamicos, en donde el usuario introduce un numero de temperaturas, tengo que ordenarlas por el metodo burbuja y sacar la media, no se que este haciendo mal que el programa me lo corre todo feo, alguien puede ayudarme y decirme mis errores porfas gacias.
este es el codigo:
Dim sum As Integer, aux As Integer
Private Sub Command1_Click()
Dim arrtemp()
total = Val(Text1.Text)
ReDim arrtemp(total)
For i = 0 To total
arrtemp(i) = InputBox("introduce las temperaturas")
Print arrtemp(i)
Next i
aux = 0
For i = 0 To (total - 1)
For j = 0 To (total - 1)
If arrtemp(j) > arrtemp(j + 1) Then
aux = arrtemp(j)
arrtemp(j) = arrtemp(j + 1)
arrtemp(j + 1) = aux
End If
List1.AddItem arrtemp(j)
Next j
sum = 0
sum = sum + arrtemp(i)
MEDIA = sum / total
Label2.Caption = MEDIA
Next i
End Sub
este es el codigo:
Dim sum As Integer, aux As Integer
Private Sub Command1_Click()
Dim arrtemp()
total = Val(Text1.Text)
ReDim arrtemp(total)
For i = 0 To total
arrtemp(i) = InputBox("introduce las temperaturas")
Print arrtemp(i)
Next i
aux = 0
For i = 0 To (total - 1)
For j = 0 To (total - 1)
If arrtemp(j) > arrtemp(j + 1) Then
aux = arrtemp(j)
arrtemp(j) = arrtemp(j + 1)
arrtemp(j + 1) = aux
End If
List1.AddItem arrtemp(j)
Next j
sum = 0
sum = sum + arrtemp(i)
MEDIA = sum / total
Label2.Caption = MEDIA
Next i
End Sub
Valora esta pregunta


0