已知一个数列的前三个数是1,2,3,从第四个数起,每个数都是前三个数之和.编程求出该数列的第35个数.
1个回答
展开全部
VB实现代码:
Private Sub Form_Click()
Dim a() As Long, strg As String
Dim i As Integer
ReDim a(3)
a(1) = 1: a(2) = 2: a(3) = 3
For i = 4 To 35
ReDim Preserve a(i)
a(i) = a(i - 1) + a(i - 2) + a(i - 3)
Next i
For i = 1 To 35
strg = strg & a(i) & " "
If i Mod 5 = 0 Then strg = strg & vbCrLf '数列每5个数显式为一行
Next i
Me.Cls '清空窗体
Print strg
Print "该数列的第35个数是:" & a(35)
End Sub
运行效果
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询