[单项选择题] 设有如下程序: Private Sub Form_Click() Dim s As Long, f As Long Dim n As Integer, i As Integer

15 查阅

[单项选择题] 设有如下程序:

Private Sub Form_Click()

Dim s As Long, f As Long

Dim n As Integer, i As Integer

f=1

n=4

For i=1 To n

f=f*i

s=s+f

Next i

Print s

End Sub

程序运行后,单击窗体,输出结果是( )。

A.32

B.33

C.34

D.35

参考答案:

B

本题是一个典型的For循环结构,f的值在每次循环中都会乘上当前的循环变量,然后累加到变量s中,循环共执行4次,即1+1*2+1*2*3+1*2*3*4=33。

计算机考试