51 lines
1.1 KiB
Text
51 lines
1.1 KiB
Text
' FB 1.05.0 Win64
|
|
|
|
' Deduces the step, n, from the length of the dynamic array passed in
|
|
' and fills it out to 'size' elements
|
|
Sub fibN (a() As Integer, size As Integer)
|
|
Dim lb As Integer = LBound(a)
|
|
Dim ub As Integer = UBound(a)
|
|
Dim length As Integer = ub - lb + 1
|
|
If length < 2 OrElse length >= size Then Return
|
|
ub = lb + size - 1
|
|
Redim Preserve a(lb To ub)
|
|
Dim sum As Integer
|
|
For i As Integer = lb + length to ub
|
|
sum = 0
|
|
For j As Integer = 1 To Length
|
|
sum += a(i - j)
|
|
Next j
|
|
a(i) = sum
|
|
Next i
|
|
End Sub
|
|
|
|
Sub printSeries(a() As Integer, name_ As String) '' name is a keyword
|
|
Print name_; " =>";
|
|
For i As Integer = LBound(a) To UBound(a)
|
|
Print Using "####"; a(i);
|
|
Print " ";
|
|
Next
|
|
Print
|
|
End Sub
|
|
|
|
Const size As Integer = 13 '' say
|
|
Redim a(1 To 2) As Integer
|
|
a(1) = 1 : a(2) = 1
|
|
fibN(a(), size)
|
|
printSeries(a(), "fibonacci ")
|
|
Redim Preserve a(1 To 3)
|
|
a(3) = 2
|
|
fibN(a(), size)
|
|
printSeries(a(), "tribonacci")
|
|
Redim Preserve a(1 To 4)
|
|
a(4) = 4
|
|
fibN(a(), size)
|
|
printSeries(a(), "tetranacci")
|
|
erase a
|
|
Redim a(1 To 2)
|
|
a(1) = 2 : a(2) = 1
|
|
fibN(a(), size)
|
|
printSeries(a(), "lucas ")
|
|
Print
|
|
Print "Press any key to quit"
|
|
Sleep
|