vb题“利用数组的知识实现从键盘终端输入一组无序数,利用冒泡排序的方式将该数值有序输出(注:无序数
Dim a() As Integer, n As Integer
Private Sub Command1_Click()
n = Val(InputBox("请问要输入几个数:"))
ReDim a(n)
For i = 1 To n
a(i) = Val(InputBox("A(" & i & ")="))
Text1.Text = Text1.Text & a(i) & " "
Next i
End Sub
Private Sub Command2_Click()
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
For i = 1 To n
Text2.Text = Text2.Text & a(i) & " "
Next i
End Sub
Private Sub Form_Load()
Text1.Text = ""
Text2.Text = ""
End Sub