控件自己加text1,list1,command1,labelmax,labelmin,labelavg,代码如下(已调试成功):
Private Sub Command1_Click()
Dim i As Integer, avg As Integer
For i = 1 To 10
Randomize
List1.AddItem Int(Rnd * 90) + 10
Next i
Dim a(1 To 10) As Integer
For i = 1 To 10
a(i) = List1.List(i - 1)
Next i
For i = 1 To 10
For j = 1 To 9
If a(j) > a(j + 1) Then
temp = a(j)
a(j) = a(j + 1)
a(j + 1) = temp
End If
Next j
Next i
Text1.Text = ""
For i = 1 To 10
Text1.Text = Text1.Text & " " & a(i)
avg = avg + a(i)
Next i
LabelMax.Caption = a(10)
LabelMin.Caption = a(1)
LabelAvg.Caption = avg / 10
End Sub
dim num(9) as integer
dim min,max as integer, avg as single
private sub form_load()
dim i
for i=0 to 9
num(i)=0
next
end sub
private sub command1_click()
dim i
for i = 0 to 9
num(i)=int( rnd*90 )+ 10
list1.additem num(i)
next i
end sub
private sub command2_click()
dim i,j
for i=0 to 8
for j = i +1 to 9
if num(i)>num(j) then
k=num(i)
num(i)=num(j)
num(j)=k
end if
next j
next i
min = num(0)
max = num(9)
avg=0
for i = 0 to 9
avg=avg+num(i)
next
avg=avg/10
print min,max,avg
end sub