[单项选择题] 单击命令按钮时,下列程序的执行结果是()。  Private Sub Commandl_Click( )    BT 4  End Sub  PriVate Sub BT(x As I

11 查阅

[单项选择题] 单击命令按钮时,下列程序的执行结果是()。  Private Sub Commandl_Click( )    BT 4  End Sub  PriVate Sub BT(x As Integer)    X=X * 2 + 1    If x <6 Then     Call BT(x)    End If    X=x * 2    Print x;  End Sub

A.15

B.16

C.17

D.18

参考答案:

D

此题在函数调用过程中采用了简单递归的方式,具体流程如下:主调过程调用BT过程,把实参4传递给BT过程中的形参x,由x=x*2+1语句推出 x=9,此时不满足BT过程体中判断语句的判断条件,执行x=x*2;Print x;语句。由x =x*2语句得到x值为18并输出,结束此次调用过程,返回到主调过程结束程序,输出结果为18。

计算机考试