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

Public Function s(n As Integer) As Long If n = 1 Then s = 1 Else s=n * s(n-1) End If End Function Private Sub Form_Click() Print “s(5)=”;s(5) End Sub

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

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

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

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

请问,你是要干嘛, 是求阶乘么,那么麻烦干嘛 Private Sub Form_Load() MsgBox fun(6), 48, "over" End Sub Function fun(byval num As Integer) as integer if num>0 then fun= num *fun(num-1) else fun=1 end function

我给你一个最简单的递归函数,求:s=1+2+3+...+n Private Sub Command1_Click() Dim n As Integer Dim S As Integer n = 100 S = MySum(n) Print S End Sub '自定义递贵函数MySum Private Function MySum(ByVal n As Integer) As Integer If...

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