求VB编程代码(For循环).题目:求Fibonacci数列:1,1,2,3,5,8,…的前40个数即:F1=1 (n=1), F2=l (n=2),Fn=F(n-l) F(n-2) (n>=3)谢谢
问题描述:
求VB编程代码(For循环).题目:求Fibonacci数列:1,1,2,3,5,8,…的前40个数
即:F1=1 (n=1), F2=l (n=2),Fn=F(n-l) F(n-2) (n>=3)谢谢
答
Private Sub Form_Click()Dim a(1 To 40) As LongFor i = 1 To 40If i = 1 Or i = 2 Thena(i) = 1Elsea(i) = a(i - 2) + a(i - 1)End IfPrint a(i); Tab;If i Mod 5 = 0 Then PrintNext iEnd Sub