If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: fibonacci number

Originally Posted by Jose M

Apararently it should work the same.

Maybe you didn't copy right? Why don't you ask the one who wrote the code!

From a principal standpoint, the two approaches you're trying here are iteration and recursion and they will look very different. You simply have to understand what you're doing to get it right. Insight first.

Re: fibonacci number

recursion:
When a function makes use of calls to itself to get it's job done.

I have some slight objections to calling the other way "iteration", more correctly would be "non-recursive" or "without recursion".

THe issue here being that you can solve fib(n) in several different non-recursive ways which may not even be iterative, and you can even use recursion without the double recursion as used here (which makes it terribly slow for larger values).