Private Sub Command1_Click() Dim s% s=f(5) Print "s="; s End Sub Privat
写出下列事件过程的执行结果。 Private Sub Command1_Click() Dim s% s=f(5) Print "s="; s End Sub Private Function f(ByVal n As Integer) If n=1 Then f=1 Else f=n+f(n - 1) End If End Function
写出下列事件过程的执行结果。 Private Sub Command1_Click() Dim s% s=f(5) Print "s="; s End Sub Private Function f(ByVal n As Integer) If n=1 Then f=1 Else f=n+f(n - 1) End If End Function
答案:Private Sub Command1_Click()
Dim s%
s = f(5)
Print "s="; s
End Sub
Private Function f(ByVal n As Integer)
If n = 1 Then
f = 1 '递归结束
Else
f = n + f(n - 1) '递归调用,每次调用变量-1,直到为1,其实就是累加1+2+。。。+5=15
End If
End Function
's=15
其他:在窗体上打印出:s=15
上一个:在form1的窗体上有一个label1的标签 运行时不按下鼠标的任何键 鼠标移动时在标签上显示鼠标光标的横坐标
下一个:vb 1*2*3*……*10