窗体上有一个名称为Command1的命令按钮,并有如下程序代码: Option Base 1 Private Sub Command1_Click() Dim a(4,4)As Integer Dim b As Integer Dim i As Integ

admin2020-04-18  35

问题 窗体上有一个名称为Command1的命令按钮,并有如下程序代码:
Option Base 1
Private Sub Command1_Click()
Dim a(4,4)As Integer
Dim b As Integer
Dim i As Integer,j As Integer
For i=1 To 4
For j=1 To 4
a(i,j)=i+j
Next j
Next i
Call f(a,B)
Print b
End Sub
Private Sub f(x()As Integer,ByRefy As Integer)
y=0
For i=1 To 4
y=y+x(i,i)
Next
End Sub
运行程序,单击命令按钮后,窗体上显示的是

选项 A、0
B、2
C、8
D、20

答案D

解析 Command1_Click()中通过嵌套循环给数组a元素赋初值,执行完后a(1,1)=2,a(2,2)=4,a(3,3)=6,a(4,4)=8;Call f(a,B)语句调用子函数Sub f(x()As Integer,ByRef y As Integer)。该函数内For循环把a数组中一维下标和二维下标相同的元素值相加。值为20,选D。
转载请注明原文地址:https://kaotiyun.com/show/2STp777K
0

随机试题
最新回复(0)