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

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

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

Private Function gcd(n As Integer, m As Integer) As Integer Dim k As Integer, max As Integer, min As Integer '定义一个大数的变量max,一个小数的变量 If n > m Then '如果n大,那么 max = n 'n是大数 min = m 'm是小数 Else max = m min...

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

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

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