vb用通项公式求菲波那切数列
答案:2 悬赏:60
解决时间 2021-11-16 20:44
- 提问者网友:晨熙污妖王
- 2021-11-16 06:56
vb用通项公式求菲波那切数列
最佳答案
- 二级知识专家网友:统治我的世界
- 2021-11-16 07:55
Private Sub Command1_Click()
Dim i As Integer
For i = 0 To 10
Print f(i)
Next
End Sub
Public Function f(x As Integer) As Integer
If x > 1 Then
f = f(x - 2) + f(x - 1)
Else
f = 1
End If
End Function
Dim i As Integer
For i = 0 To 10
Print f(i)
Next
End Sub
Public Function f(x As Integer) As Integer
If x > 1 Then
f = f(x - 2) + f(x - 1)
Else
f = 1
End If
End Function
全部回答
- 1楼网友:蜜罐小熊
- 2021-11-16 08:55
private sub command1_click()
dim a(1 to 10) as integer
for i = 1 to 10
if i = 1 or i = 2 then
a(i) = 1
else
a(i) = a(i - 1) + a(i - 2)
end if
print i, a(i)
next i
end sub
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯