Demonstrating Fibonacci sequence recursively : Recursive Function « Class Module « VB.Net Tutorial






Public Class Tester
   Public Shared Sub Main
      Dim number As Integer = 13

      Console.WriteLine("Fibonacci Value is " & Fibonacci(number))


   End Sub 
   ' calculate Fibonacci value recusively 
   Shared Function Fibonacci(ByVal number As Integer) As Long

      ' check for base cases
      If number = 1 OrElse number = 0 Then
         Return number
      Else
         Return Fibonacci(number - 1) + Fibonacci(number - 2)
      End If

   End Function ' Fibonacci

End Class
Fibonacci Value is 233








6.8.Recursive Function
6.8.1.Recursively generates factorial of number
6.8.2.Demonstrating Fibonacci sequence recursively