在窗体上放置一个命令按钮Command1,并编写下列单击事件的程序: Option Base 1 Private Sub Command1_Click() Dim c As Integer,d As Integer d=0

admin2010-03-30  17

问题 在窗体上放置一个命令按钮Command1,并编写下列单击事件的程序:    Option Base 1    Private 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 j        Print d    End Sub    程序运行后,单击命令按钮,则在窗体上输出的内容为(    )。

选项 A、10
B、12
C、16
D、20

答案2

解析 程序首先使用Array函数为x数组变量赋值,然后利用For循环和If结构语句实现程序功能。程序执行过程如下: ①当i=1时,X()=2;d=d-c=-6;②当i=2时,X(i);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。
转载请注明原文地址:https://kaotiyun.com/show/Qa1p777K
0

最新回复(0)