Advertisement
mudri

Fibonacci VB.NET iterative

Jun 4th, 2013
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.35 KB | None | 0 0
  1. Function GetNthFibonacciNumber(ByVal n As Integer) As Integer
  2.     Dim NextLast As Integer, Last As Integer, This As Integer
  3.     If n = 0 Then
  4.         Return 0
  5.     ElseIf n = 1 Then
  6.         Return 1
  7.     Else
  8.         NextLast = 0 : Last = 1
  9.         For i As Integer = 2 To n
  10.             This = NextLast + Last
  11.             NextLast = Last
  12.             Last = This
  13.         Next i
  14.         Return This
  15.     End If
  16. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement