用VB编程,求Fibonacci数列的前40个数以及它们的和.数列特点:第1,2两个数为1,从第三个数开始,每个数等于前两个数之和.

问题描述:

用VB编程,求Fibonacci数列的前40个数以及它们的和.
数列特点:第1,2两个数为1,从第三个数开始,每个数等于前两个数之和.

Option Explicit
Dim f(40) As Long
Private Sub Command1_Click()
Dim i As Byte
Dim s As Long
f(1) = 1
f(2) = 1
s = 2
Print "No1: " & f(1)
Print "No2: " & f(2)
For i = 3 To 40
f(i) = f(i - 1) + f(i - 2)
s = s + f(i)
Print "No" & i & ": " & f(i)
Next
Print "总和: " & s
End Sub