chamsi09

Untitled

Nov 14th, 2024
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.49 KB | None | 0 0
  1. Module Module1
  2.     Sub Main()
  3.         Dim n As Integer = 10 ' Example input
  4.         Dim result As Integer = Fibonacci(n)
  5.         Console.WriteLine("Fibonacci(" & n & ") = " & result)
  6.     End Sub
  7.  
  8.     Function Fibonacci(n As Integer) As Integer
  9.         If n = 0 Then ' Base case 1
  10.             Return 0
  11.         ElseIf n = 1 Then ' Base case 2
  12.             Return 1
  13.         Else ' Recursive case
  14.             Return Fibonacci(n - 1) + Fibonacci(n - 2)
  15.         End If
  16.     End Function
  17. End Module
Advertisement
Add Comment
Please, Sign In to add comment