有如下事件过程: Private Sub Form_Load() Show Dim Arr() As Variant Arr = Array(1, 3, 5, 7, 9, 11, 13, 15) Call converse(

admin2015-09-23  38

问题 有如下事件过程:
Private Sub Form_Load()
    Show
    Dim Arr() As Variant
    Arr = Array(1, 3, 5, 7, 9, 11, 13, 15)
    Call converse(Arr)
    For i = 0 To 7
        Print arr(i);
    Next i
End Sub
    以上程序的功能是,通过调用Converse过程,将数组Arr中的元素逆序存放并输出。过程Converse的正确代码是

选项 A、Private Sub converse(dim a() as Variant )
Dim T
For i = LBound(A) To UBound(A)
T = a(i)
a(i) = a(UBound(A) - i)
a(UBound(A) - i) = T
Next i
End Sub
B、Private Sub converse(dim a() as Variant)
Dim T
Dim J As Integer
J = (LBound(A) + UBound(A)) / 2
For i = LBound(A) To J
T = a(i)
a(i) = a(UBound(A) - i)
a(UBound(A) - i) = T
Next i
End Sub
C、Private Sub converse(a() As Variant)
Dim T
For i = LBound(A) To UBound(A)
T = a(i)
a(i) = a(UBound(A) - i)
a(UBound(A) - i) = T
Next i
End Sub
D、Private Sub converse(a() As Variant)
Dim T
Dim J As Integer
J = Int((LBound(A) + UBound(A)) / 2)
For i = LBound(A) To J
T = a(i)
a(i) = a(UBound(A) - i)
a(UBound(A) - i) = T
Next i
End Sub

答案D

解析 采用for循环的方式,实现将数组元素逆序排列,判断循环终止的条件为数组A的最小下标和最大下标和的一半,并且定义变量T,作为中间变量用来互换中心对称的元素。故正确答案为选项D。
转载请注明原文地址:https://kaotiyun.com/show/PGLp777K
0

最新回复(0)