Feb 17, 2008

Output Fibonacci number without recurrence.

It is possible to write a code for Fibonacci number without recurrence.
Alternatively the code include a loop.


def fib(n)
a, b, c = 0, 1, 0

n.times do
c = a
a = b
b += c
end

a
end

p fib(10)

No comments: