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

Text1.Text = f(Val(Text1.Text)) 表示的意思是先把传入的文本字段Text1.Text 利用val 函数转化为int数值。然后调用自定义的递归函数 f (n as Integer) ,并把刚转化为int的数值作为参数传入其中,经过递归函数运算得到的结果作为返回值并赋值给...

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

Private Sub Command1_Click() Label3.Caption = "转换后的" & Val(Text2.Text) & "进制数为" + Transformation(Val(Text1.Text), Val(Text2.Text))End SubPrivate Function Transformation(ByVal n As Long, ByVal k As Integer) As String If ...

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

不适用递归算法。用循环。 for i = 1 to d a=a*(1+ c/100) +b next i print a

对于函数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为止,也就是知道满足参数等...

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

Private Sub Command1_Click() n = CInt(InputBox("请要求几的阶乘?")) MsgBox (n & "!=" & fact(n)) End Sub Function fact(n) s = 1 For i = 2 To n s = s * i Next i fact = s End Function

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