Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Module Module1
- Sub Main()
- Dim n As Integer = 10 ' Example input
- Dim result As Integer = Fibonacci(n)
- Console.WriteLine("Fibonacci(" & n & ") = " & result)
- End Sub
- Function Fibonacci(n As Integer) As Integer
- If n = 0 Then ' Base case 1
- Return 0
- ElseIf n = 1 Then ' Base case 2
- Return 1
- Else ' Recursive case
- Return Fibonacci(n - 1) + Fibonacci(n - 2)
- End If
- End Function
- End Module
Advertisement
Add Comment
Please, Sign In to add comment