问题 单项选择题

在窗体上放置一个命令按钮Command1,并编写下列单击事件的程序: Option Base 1 Pdvate Sub Command1_Click() Dim c As Integer,d As Integer d=0 c=6 X=Array(2,4,6,8,10,12) For i=1 To 6 If X(i)>c Then d=d+X(i) c=X(i) Else d=d-c End If Next i Print d End Sub 程序运行后,单击命令按钮,则在窗体上输山的结果是( )。

A.10

B.12

C.16

D.20

答案

参考答案:B

解析: 程序首先使用Array函数为x数组变量赋值,然后利用For循环和If结构语句实现程序功能。程序执行过程如下: ①当i=1时,X(i)=2,d=d-c=-6;②当i=2时,X(i)=4,d=d-c=-12;③当i=3时,X(i)=6,d=d-c=-18;④当i=4时,X(i)=8,d=d+X(i)=-10,c=8;⑤当i=5时,X(i)=-10,d=d+X(i)=0,c=10;⑥当i=6时,X(i)=12,d=d+X(i)=12,c=12。

填空题
单项选择题