35 lines
941 B
Plaintext
35 lines
941 B
Plaintext
print "Rosetta Code - Fibonacci sequence": print
|
|
print " n Fn"
|
|
for x=-12 to 12 '68 max
|
|
print using("### ", x); using("##############", FibonacciTerm(x))
|
|
next x
|
|
print
|
|
[start]
|
|
input "Enter a term#: "; n$
|
|
n$=lower$(trim$(n$))
|
|
if n$="" then print "Program complete.": end
|
|
print FibonacciTerm(val(n$))
|
|
goto [start]
|
|
|
|
function FibonacciTerm(n)
|
|
n=int(n)
|
|
FTa=0: FTb=1: FTc=-1
|
|
select case
|
|
case n=0 : FibonacciTerm=0 : exit function
|
|
case n=1 : FibonacciTerm=1 : exit function
|
|
case n=-1 : FibonacciTerm=-1 : exit function
|
|
case n>1
|
|
for x=2 to n
|
|
FibonacciTerm=FTa+FTb
|
|
FTa=FTb: FTb=FibonacciTerm
|
|
next x
|
|
exit function
|
|
case n<-1
|
|
for x=-2 to n step -1
|
|
FibonacciTerm=FTa+FTc
|
|
FTa=FTc: FTc=FibonacciTerm
|
|
next x
|
|
exit function
|
|
end select
|
|
end function
|