现有如下程序: Private Sub Command1_Click()   s=0   For i=1 To 5     s=s+f(5+i)   Next   Print s End Sub Public Function f(x As Integer

admin2015-10-23  37

问题 现有如下程序:
Private Sub Command1_Click()
  s=0
  For i=1 To 5
    s=s+f(5+i)
  Next
  Print s
End Sub
Public Function f(x As Integer)
  If x>=10 Then
    t=x+1
  Else
    t=x+2
  End If
  f=t
End Function
    运行程序,则窗体上显示的是(  )。

选项 A、38
B、49
C、61
D、70

答案B

解析 程序中过程f的功能是参数值大于等于10时,返回参数加1的值,否则返回参数加2的值。因此按钮事件中s值的计算过程如下:
    i=1时,s=0+f(5+1)=8;
    i=2时,s=8+f(5+2)=8+9=17;
    i=3时,s=17+f(5+3)=17+10=27;
    i=4时,s=27+f(5+4)=27+11=38;
    i=5时,s=38+f(5+5)=38+11=49;
    因此最终在窗体上输出的是49。
转载请注明原文地址:https://kaotiyun.com/show/3WLp777K
0

最新回复(0)