题库 题库

【简答题】

 
Option Base 1
Private Sub Sort(a() As Integer)
    Dim Start As Integer, Finish As Integer
    Dim i As Integer, j As Integer, t As Integer
    'Start = ?(a)
    'Finish = ?(a)
    'For i = ? To 2 Step -1
        'For j = 1 To ?
            'If a(j) ? a(j + 1) Then
                t = a(j + 1)
                a(j + 1) = a(j)
                a(j) = t
            End If
        Next j
    Next i
End Sub
Private Sub Command1_Click()
    Dim arr1
    Dim arr2(4) As Integer
    arr1 = Array(Val(Text1.Text), Val(Text2.Text), Val(Text3.Text), Val(Text4.Text))
    For i = 1 To 4
        arr2(i) = CInt(arr1(i))
    Next i
    Sort arr2()
    Text1.Text = arr2(1)
    Text2.Text = arr2(2)
    Text3.Text = arr2(3)
    Text4.Text = arr2(4)
End Sub

参考答案

Option Base 1
Private Sub Sort(a() As Integer)
    Dim Start As Integer, Finish As Integer
    Dim i As Integer, j As Integer, t As Integer
    Start = LBound(a)
    Finish = UBound(a)
    For i = Finish To 2 Step -1
        For j = 1 To i - 1
            If a(j) < a(j + 1) Then
                t = a(j + 1)
                a(j + 1) = a(j)
                a(j) = t
            End If
        Next j
    Next i
End Sub
Private Sub Command1_Click()
    Dim arr1
    Dim arr2(4) As Integer
    arr1 = Array(Val(Text1.Text), Val(Text2.Text), Val(Text3.Text), Val(Text4.Text))
    For i = 1 To 4
        arr2(i) = CInt(arr1(i))
    Next i
    Sort arr2()
    Text1.Text = arr2(1)
    Text2.Text = arr2(2)
    Text3.Text = arr2(3)
    Text4.Text = arr2(4)
End Sub

相关试题