a(i) = a(i - 1) + a(i - 3) 怎么用VB 编程
答案:4 悬赏:10 手机版
解决时间 2021-11-18 11:08
- 提问者网友:送舟行
- 2021-11-18 06:04
a(i) = a(i - 1) + a(i - 3) 怎么用VB 编程
最佳答案
- 五星知识达人网友:夜余生
- 2021-11-18 06:58
用递归就好了。
Function a(i As Long) As Long
If i = 1 Then
a = 1
ElseIf i = 2 Then
a = 2
ElseIf i = 3 Then
a = 3
Else
a = a(i - 1) + a(i - 3)
End If
End Function
Function a(i As Long) As Long
If i = 1 Then
a = 1
ElseIf i = 2 Then
a = 2
ElseIf i = 3 Then
a = 3
Else
a = a(i - 1) + a(i - 3)
End If
End Function
全部回答
- 1楼网友:归鹤鸣
- 2021-11-18 09:58
for i=4 to n
a(i)=a(i-1)+a(i-3)
next i
a(i)=a(i-1)+a(i-3)
next i
- 2楼网友:玩世
- 2021-11-18 09:08
Function calc1(i As Long) As Long
If i = 1 Then
return 1
ElseIf i = 2 Then
return 2
ElseIf i = 3 Then
return 3
Else
return calcvb(1,2,3,i,4)
End If
End Function
Function calcvb(a1 As Long, a2 As Long, a3 As Long,i As Long,x As Long) As Long
dim a4 as Long
a4 = a3 - a1
if x = i then
return a4
else
x = x + 1
return calcvb(a2,a3,a4,i,x)
endif.
End Function
If i = 1 Then
return 1
ElseIf i = 2 Then
return 2
ElseIf i = 3 Then
return 3
Else
return calcvb(1,2,3,i,4)
End If
End Function
Function calcvb(a1 As Long, a2 As Long, a3 As Long,i As Long,x As Long) As Long
dim a4 as Long
a4 = a3 - a1
if x = i then
return a4
else
x = x + 1
return calcvb(a2,a3,a4,i,x)
endif.
End Function
- 3楼网友:千夜
- 2021-11-18 07:40
代码如下:
for i=4 to n
a(i)=a(i-1)+a(i-3)
next
for i=4 to n
a(i)=a(i-1)+a(i-3)
next
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯