1个回答
2009-04-04
展开全部
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询