wzkl.net
当前位置:首页 >> VB递归算法原理? >>

VB递归算法原理?

对于函数z(a),当a=1时,即z(1)=x,z(2)=y,在本例中a=5,则 z(5)=z(3)+z(4) z(3)=z(1)+z(2)=x+y; z(4)=z(2)+z(3)=y+z(3)=y+x+y 所以z(5)=(x+y)+(y+x+y)=2x+3y=13 递归调用的原理就是递推,知道函数的参数满足z=x或者z=y为止,也就是知道满足参数等...

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...

窗体中放入Text控件和命令按钮.取text中的数字作为N代码如下Private Function F(n As Long) As Long If n > 2 Then F = F(n - 1) + F(n - 2) Else F = 1 End If End FunctionPrivate Sub Command1_Click() Cls Dim I As Long I = Val(Text1.Text...

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...

Private Sub Command1_Click() n = CInt(InputBox("N=")) y = fac(n) MsgBox n & "!=" & y End Sub Function fac(n) If n = 0 Or n = 1 Then fac = 1 Else fac = n * fac(n - 1) End Function

Private Sub sub1(x As Integer) x = x * 2 + 1 If x < 10 Then Call sub1(x)'这句是重点,当你输入2运行到这里的时候是5小于10然后进入了这个CALL,这时候是重新开始了,等于是你的开始值是5,开始得到的是11,这时候就不会进这个CALL了,这个C...

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("请...

首先VB是不推荐用递归算法的,效率太低,建议用循环做 然后你的dm是string,那么它咋就能作为二维数组的下标呢? 再说你的条件是 ri = TabA(i, 0) ,不是 ri=tab(i,dm)啊?

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