Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Fibonacci

Name: Anonymous 2008-04-21 14:38

Hi

I need some help with calculating Fibonacci
N is an output that shows the Fibonacci numbers

-- Begin
N <= 0 -> N=1 A=1 B=1 C=1 D=1;
N=A+B
C=N
N=B+C
D=N
N=C+D
B=N
N=D+B
A=N
-- Restart at begining

Any idea what I did wrong? I can't figure it out

Name: Anonymous 2008-04-21 15:47

I don't understand what you wrote but here is the iterative version. fib(n) gives the nth fibonacci number.

fib(n) = f(n,1,0) where
f(m,a,b) = b if m=0 else f(m-1,a+b,a)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List