VB随机产生10个两位数整数(正整数),要求分别用选择排序法和冒泡排序法将这10个数降序排列输出在窗体上
收起
知与谁同
2018-07-20 13:14:12
3273
0
1
条回答
写回答
取消
提交回答
-
Option Base 1
Dim a(20)
Private Sub Form_Load()
Randomize
For i = 1 To 10
a(i) = Int(10 + 90 * Rnd)
Next
End Sub
Private Sub Command1_Click() '选择排序法
For i = 1 To 9
For j = i + 1 To 10
If a(j) > a(i) Then t = a(i): a(i) = a(j): a(j) = t
Next j
Next i
For i = 1 To 10
Print a(i);
Next
Print
End Sub
Private Sub Command2_Click() '冒泡排序法
For i = 1 To 9
For j = 10 To i + 1 Step -1
If a(j - 1) < a(j) Then
t = a(j - 1): a(j - 1) = a(j): a(j) = t
End If
Next j
Next i
For i = 1 To 10
Print a(i);
Next
Print
End Sub
2019-07-17 22:49:40