Fibonacci numbers in Basic
Example for versions
VBScript 5.7,
VBScript 5.8
This program calculates Fibonacci numbers recursively. Note the absence of a lot of elements typical for other Basic dialects: variable declarations and function return type, explicit number-to-string conversion before concatenation etc.
Function Fibonacci(N)
If N < 2 Then
Fibonacci = N
Else
Fibonacci = Fibonacci(N - 1) + Fibonacci(N - 2)
End If
End Function
For i = 1 To 16
res = res & Fibonacci(i) & ", "
Next
WScript.Echo (res & "...")
Comments
]]>blog comments powered by Disqus
]]>