|
Fibonacci Value
The fibonacci series goes something like this
0 , 1 , 1, 2, 3 , 5 , 8 , 13 , 21
It begins with 0 and 1 and it has the property
that each subsequent Fibonacci number is the sum of the 2 previous
Fibonacci numbers . The ratio of successive Fibonacci numbers
has a constant value 0f 1.618 . The function below will take
an integer and evaluate its fibonacci value.
Here is the function
<%
Function Fibonacci(ByVal intNumber)
If (intNumber = 0 Or intNumber = 1) Then
Fibonacci = intNumber
Else
Fibonacci = Fibonacci(intNumber - 1) + Fibonacci(intNumber -
2)
End If
End Function
%>
And here is how we test the function
<%
'variables to store our numbers
Dim fib1 , fib2
'a couple of values
fib1 = 22
fib2 = 3
'display fibonacci value of values e.g Fibonacci(3)
Response.Write ("The Fibonacci value of " & fib1
& " is " & Fibonacci(fib1) & "<br>")
Response.Write ("The Fibonacci value of " & fib2
& " is " & Fibonacci(fib2) & "<br>")
%>
|