wzkl.net
当前位置:首页 >> VB中递归的用法: >>

VB中递归的用法:

Private Sub Form_load() Dim i As Long,n as integer n=int(val(inputbox("输入Fibonacci数列的项数"))) For i = 1 To n Print Fibonacci(i) Next End Sub Private Function Fibonacci(n As Long)As Long If n = 1 Then Fibonacci = 1 ElseIf n...

Private Sub Form_load() Dim i As Long,n as integer n=int(val(inputbox("输入Fibonacci数列的项数"))) For i = 1 To n Print Fibonacci(i) Next End Sub Private Function Fibonacci(n As Long)As Long If n = 1 Then Fibonacci = 1 ElseIf n...

Private Sub Command1_Click() Dim a As Integer, b As Integer a = Text1 b = Text2 Text3 = gcd(a, b) End Sub Function gcd(ByVal a As Integer, ByVal b As Integer) As Integer If a Mod b = 0 Then gcd = b Else gcd = gcd(b, a Mod b) En...

Form1上放一个文本框Text1, 一个按钮Command1。 在框中输入某个数字,例如10,代码会将列出f(1)至f(10)的值。 如果你只需要特定的第n项,比如第8项,就直接调用DiGui(8)即可。 代码: Private Sub Command1_Click() Dim n As Long n = CInt(Tex...

最后一行打印的并不是最后一次a的值(1),而是第一次递归调用时a的值(2)。

Function Factorial(n As Integer) As DoubleIf Factorial = 0 Then Factorial = 1If n > 1 Then Factorial = n * Factorial(n - 1)End FunctionPrivate Sub Form_Click() '点击窗体运行MsgBox "阶乘计算结果为 " & Factorial(Val(InputBox("请...

第1题: 添加一个按钮,完整代码如下: Option Explicit Private Sub Command1_Click() Print Y(20) End Sub Private Function Y(ByVal n As Integer) As Single If n = 1 Then Y = 2 / 1 Else Y = (n + 1) / n + Y(n - 1) End If End Function ...

Option ExplicitDim p&, c&, m%, n%Private Sub Command1_Click() n = InputBox("输入n(n>=m)") m = InputBox("输入m(n>=m)") If n >= m Then p = fac(n) / fac(n - m) c = p / fac(m) Picture1.Print " P("; n; ","; m; ")="; p Picture1.Print...

开始 x=2 x=x*2+1=5 小于6所以进入第二次book x=5 x=x*2+1=11 大于6 x = x * 2 + 1=23 窗口打印23 返回第一次注意这里x=23了(因为VB默认是地址传递) x = x * 2 + 1=47 窗口打印47 结束

Private Sub Form_Click() Print fact(4)End SubPublic Function fact(n As Integer) As Long If n = 1 Then fact = 1 Else fact = n * fact(n - 1) End If 'Print fact;End Function

网站首页 | 网站地图
All rights reserved Powered by www.wzkl.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com