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

因为还没来得及输出),就进入了递归: 1. 输出一个( 2. n=n+1 3.1. 如果 n

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

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

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

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

窗体中放入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...

第一个: A、VB的过程可分为函数过程(Function过程)和Sub过程,这句话是对的; B、无论是函数过程,还是Sub过程,均可以用一定的条件来实现递归,因此此句不对; C、子过程,在这里应该说的是Sub过程,在主程序中,可以按一定方式向子程序传递...

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