(32)在窗体上画一个名为Commandl的命令按钮,然后编写如下代码: Option Base 1 Private Sub Commandl_Click() Dim a a=Array(1,2,

admin2020-02-27  13

问题 (32)在窗体上画一个名为Commandl的命令按钮,然后编写如下代码:
    Option Base 1
    Private Sub Commandl_Click()
           Dim a
           a=Array(1,2,3,4)
          j=1
          For i=4 To 1 Step-l
              S=s+a(i)*j
              j=j*10
         Next I
         Print S
    End Sub
    运行上面的程序,其输出结果是(     )。

选项 A、1234
B、12
C、34
D、4321

答案A

解析 Array函数用来为数组元素赋值,即把一个数据集读入某个数组。其格式为:数组变量名=Array(数组元素值)。Dim a语句没有变量类型名,则a默认为Variant类型,这里它作为数组变量使用。现在已知数组a 中元素的值依次为1、2、3、4,则For循环中各变量值变化如下:
    i=4时,s=s+a(4)*j=O+4*1=4,j=1*10=10
    i=3时,s=s+a(3)*j=4+3*10=4十30=34,j=10*10=100
    i=2时,s=s+a(2)*j=34+2*100=34+200=234,j=100*10=1000
    i=1时,s=s+a(1)*j=234+1*1000=234+1000=1234。循环结束。s的值为1234。
转载请注明原文地址:https://kaotiyun.com/show/4PTp777K
0

随机试题
最新回复(0)