使用inputbox()函数将多个整数输入数组a,再使用冒泡法排序对对数组进行排序。
展开全部
Private Sub Form_Click()
Dim a(100) As Integer
Dim n As Integer, i As Integer, j As Integer, t As Integer
t = InputBox("请输入整数,-1表示结束:")
n = 0
Do While t <> -1
n = n + 1
a(n) = t
t = InputBox("请输入整数,-1表示结束:")
Loop
For i = 1 To n - 1
For j = 1 To n - i
If a(j) > a(j + 1) Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
Next i
Print "共输入"; n; "个有效数字,排序结果如下:"
For i = 1 To n
Print a(i);
If i Mod 10 = 0 Then Print
Next i
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询