Function with array returning 0 Visual Basic
I'm quite new at using arrays and functions in Visual Basic and I cant
seem to figure this out, my problem is that whenever I call the function
"Fibo" it returns 0 no matter the value of "n". I'm sure the error is
pretty basic...
Any pointer would be really appreciated!
Public Function fibo(n As Integer) As Integer
Dim arrayFib(n + 1) As Integer 'declare array to hold fibonacci
arrayFib(0) = 0 'idem
arrayFib(1) = 1 'declare start value
Dim i As Integer = 2 'start position
While i <= n
arrayFib(i) = arrayFib(i - 1) + arrayFib(i - 2)
i = 1 + i
Return arrayFib(i)
No comments:
Post a Comment