VB编程:输入10个二位整数数组元素,用选择法从小到大排序后输出。
发布网友
发布时间:2024-03-08 21:09
我来回答
共1个回答
热心网友
时间:2024-08-17 15:43
在窗体上添加两个图片框和一个按钮,按钮单击事件代码如下:
Private Sub Command1_Click()
Dim a(1 To 10) As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Picture1.Cls
Picture2.Cls
Randomize
'产生10个二位随机整数,并在Picture1输出
For i = 1 To 10
a(i) = Int(Rnd * 90) + 10
Picture1.Print a(i);
Next
'选择法排序
For i = 1 To 9
j = i
For k = i + 1 To 10
If a(j) > a(k) Then j = k
Next
If i <> j Then
k = a(i)
a(i) = a(j)
a(j) = k
End If
Next
'在Picture2输出排序后的数组
For i = 1 To 10
Picture2.Print a(i);
Next
End Sub