Dim str As String = "生成的数组为" & vbCrLf, sum As Integer = 0, i, j, temp As Integer
Dim a(10) As Integer
For i = 1 To 10
a(i) = Int(Rnd() * 90 + 10)
str = str & a(i) & " "
Next
str = str & vbCrLf & "排序后的数组为" & vbCrLf
For i = 1 To 10
For j = 1 To 10 - i
If a(j) < a(j + 1) Then
temp = a(j + 1)
a(j + 1) = a(j)
a(j) = temp
End If
Next j
Next i
For i = 1 To 10
str = str & a(i) & " "
sum = sum + a(i)
Next
str = str & vbCrLf
str = str & "该数组元素各个元素的和是 " & sum & " 最大元素是 " & a(1) & " 最小元素是 " & a(10)
TextBox6.Text = str
运行结果:
生成的数组为
73 58 62 36 37 79 11 78 83 73
排序后的数组为
83 79 78 73 73 62 58 37 36 11
该数组元素各个元素的和是 590 最大元素是 83 最小元素是 11