Module Module1 ' program fibonacci.py ' recursive algorithm to calculate the numbers in the ' Fibonacci sequence 0,1,1,2,3,5,8.. ' in which each number after the first two ' is the sum of the previous pair of numbers ' each routine is timed ' Fibonacci recursive method Function fibRecursive(ByVal inNum) If (inNum = 0) Then Return (0) ElseIf (inNum = 1) Then Return (1) Else Return (fibRecursive(inNum - 1) + fibRecursive(inNum - 2)) End If End Function ' Fibonacci iterative method Function fibIterative(ByVal inNum) As List(Of Integer) Dim i As Integer ' list of first two Fibonacci numbers Dim fibNumbers = New List(Of Integer) From {0, 1} ' now append the sum of the two previos numbers to the list For i = 2 To (inNum - 1) fibNumbers.Add(fibNumbers(i - 1) + fibNumbers(i - 2)) Next Return fibNumbers End Function Sub Main() Dim seriesLen As Integer = 0 Dim i As Integer = 0 Dim eat As String = "" Dim newFibList As List(Of Integer) Dim num As Integer = 0 Try Console.WriteLine("Select a number in the range of 3 to 30 to be the length of the fibonacci series") seriesLen = Console.ReadLine() Console.WriteLine("Recursive method") For i = 0 To (seriesLen - 1) Console.WriteLine(String.Format("{0} {1}", i + 1, fibRecursive(i))) Next Console.WriteLine("") Console.WriteLine("Iterative method") newFibList = fibIterative(seriesLen) i = 0 For Each num In newFibList Console.WriteLine(String.Format("{0} {1}", i + 1, num)) i = i + 1 Next Catch ex As Exception Console.WriteLine("Please enter a number in the range of 3 and 30 inclusive.") End Try Console.WriteLine("Any key to continue") eat = Console.ReadLine() End Sub End Module