斐波那契数列前一百项和的前五位!
来源:学生作业帮 编辑:百度作业网作业帮 分类:综合作业 时间:2024/08/19 11:38:47
斐波那契数列前一百项和的前五位!
用VB语言编一个程序可以列出斐波那契数列.
用VB语言编一个程序可以列出斐波那契数列.
![斐波那契数列前一百项和的前五位!](/uploads/image/z/8601734-38-4.jpg?t=%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0%E5%88%97%E5%89%8D%E4%B8%80%E7%99%BE%E9%A1%B9%E5%92%8C%E7%9A%84%E5%89%8D%E4%BA%94%E4%BD%8D%21)
Private Sub Command1_Click()
Dim m As Long
Dim n As Integer
n = Val(Text1.Text)
m = fabn(n)
Print m
End Sub
Private Function fabn(ByVal n As Integer) As Long
If n = 1 Or n = 2 Then
fabn = 1
Else
fabn = fabn(n - 2) + fabn(n - 1)
End If
End Function
这个最基本的了
Dim m As Long
Dim n As Integer
n = Val(Text1.Text)
m = fabn(n)
Print m
End Sub
Private Function fabn(ByVal n As Integer) As Long
If n = 1 Or n = 2 Then
fabn = 1
Else
fabn = fabn(n - 2) + fabn(n - 1)
End If
End Function
这个最基本的了