vb代码选择法排序的代码?
发布网友
发布时间:2022-05-02 18:38
我来回答
共1个回答
热心网友
时间:2022-05-22 02:43
Dim str As String = "", temp As Integer = 0, sum As Integer = 0, max As Integer
Dim a(10) As Integer
str = str & "原数组为" & vbCrLf
For i = 1 To 10 Step 1
a(i) = Int(Rnd() * 90 + 10)
str = str & a(i) & " "
Next
str = str & vbCrLf
For i = 1 To 9
max = a(i)
For j = i + 1 To 10
If a(j) > max Then
max = a(j)
temp = a(i) : a(i) = a(j) : a(j) = temp
End If
Next
Next
str = str & "排序后的数组为" & vbCrLf
For i = 1 To 10 Step 1
str = str & a(i) & " "
Next
TextBox6.Text = str