下列程序运行后,单击窗体,在窗体上显示:1,1+2,1+2+3,1+2+3+4,1+2+3+4+5的和。在横线处应填写( )。 Private Sub Form_Click() Dim i As Integer,tt As Integ

admin2016-11-12  25

问题 下列程序运行后,单击窗体,在窗体上显示:1,1+2,1+2+3,1+2+3+4,1+2+3+4+5的和。在横线处应填写(    )。
    Private Sub Form_Click()
    Dim i As Integer,tt As Integer
    For i=l To 5
    tt=Sum(i):Print"tt=";tt,
    Next i
    End Sub
    Private Function Sum(    )
    j=j+n:Sum=j
    End Function

选项 A、n As Integer    j As Integer
B、n As Integer    Static j As Integer
C、ByVal n As Integer  j As Integer
D、ByVal n As Integer  Static j As Integer

答案D

解析 本题考查参数的传递和静态局部变量。Sum函数在窗体单击事件中调用5次并用来求和,因此每一次求和结果应当保留,所以借助静态变量实现。同时要求传递的形参变化不应影响到实参,因此采用传值调用。
转载请注明原文地址:https://kaotiyun.com/show/uoGp777K
0

最新回复(0)