> 其他 >
用VB编程,求Fibonacci数列的前40个数以及它们的和.
数列特点:第1,2两个数为1,从第三个数开始,每个数等于前两个数之和.
人气:136 ℃ 时间:2020-05-22 06:09:38
解答
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
推荐
猜你喜欢
© 2024 79432.Com All Rights Reserved.
电脑版|手机版