下列程序执行后,变量S的值为 Dim s As Long,x As Integer s=0 For x=1 To 10 Step 2 s=s+x Next x Text1.Text=s

admin2010-03-30  26

问题 下列程序执行后,变量S的值为    Dim s As Long,x As Integer    s=0    For x=1 To 10 Step 2        s=s+x    Next x    Text1.Text=s

选项 A、10
B、25
C、50
D、100

答案2

解析 因为步长为2,故循环一共执行了5次。x=1时,执行s=s+x得s为1;x=3时,执行s=s+x即s=1+3(注意:此时的s是上次执行的结果值),故此时s为4;同理在x=5时,执行s=s+x得s为9;x=7时,执行s=s+x得s为16;x=9时,执行s=s +x得s为25;故最终变量s的值为25。
转载请注明原文地址:https://kaotiyun.com/show/I1mp777K
0

随机试题
最新回复(0)