用递归算法编写求斐波那契数列前n项和的程序用function定义函数
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 18:07:50
xRMO@+ڨ!JiUcLn
nvk8Q@䦆pm_pKx}͛U5jtX͠W
zVM{Ui6&^c.qعoA6GJφ߄
mĀ'@FİKҴ15[*$ag(q
,2)M7L{:;&A-K{fEבz+G\4utL7!ϷfAYb'kvY>I{>T(+eN̚5DmPZb_-ϏrBa(xuL@XxP!y&ӊcd) ѱ}ofY
用递归算法编写求斐波那契数列前n项和的程序用function定义函数
用递归算法编写求斐波那契数列前n项和的程序
用function定义函数
用递归算法编写求斐波那契数列前n项和的程序用function定义函数
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 Function
Private Sub Command1_Click()
Dim a As String
Dim i as long
Dim n as long
Dim sum as long
a = InputBox("输入斐波那契数列项数","输入")
n = Clng(a)
Cls
For i=1 to n
sum = sum + F(i)
Next
Print "斐波那契数列前";Cstr(n);"项和:";sum
End Sub