运行结果:
生成的数组为
73 58 62 36 37 79 11 78 83 73
排序后的数组为
83 79 78 73 73 62 58 37 36 11
该数组元素各个元素的和是 590 最大元素是 83 最小元素是 11
Private Sub Command1_Click()
Dim a(10) As Integer
Dim max As Integer
Dim min As Integer
Dim avg As Double
Dim sum As Integer
sum = 0
Randomize
For i = 1 To 10
If i = 1 Then
a(i) = Int(Rnd * 90 + 10)
max = a(i)
min = a(i)
sum = sum + a(i)
Else
a(i) = Int(Rnd * 90 + 10)
If a(i) > max Then max = a(i)
If a(i) < min Then min = a(i)
sum = sum + a(i)
End If
Next i
Print "最大值是" & max
Print "最小值是" & min
Print "平均值是" & sum / 10
End Sub