费波那西数列,即第n项的值为前两项的和,试编程求第n项的值

如题所述

这是我的VB代码:
Public Class Form1
Function f(ByVal n As ULong) As ULong
If n = 1 Or n = 2 Then f = 1 Else f = f(n - 2) + f(n - 1)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox2.Text = f(Val(TextBox1.Text))
End Sub
End Class
温馨提示:答案为网友推荐,仅供参考
相似回答