添加一个文本框输入前N项的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 Function
Private Sub Command1_Click()
Cls
Dim N As Long, I As Long, sum As Long
sum = 0
N = Val(Text1.Text)
For I = 1 To N
sum = sum + F(I)
Next I
Print "斐波那契数列前" & N & "项的和为:" & sum
End Sub