Re: Fibonnaci
- From: Richard Heathfield <invalid@xxxxxxxxxxxxxxx>
- Date: Fri, 9 Dec 2005 03:26:36 +0000 (UTC)
MARQUITOS51 said:
> Im trying to find any code in C developed to calculate the fibonnacci
> series with or without functions. I need a code example so I can
> studied and see how it works.
The Fibonacci series can be defined as f(0) = 0, f(1) = 1, and f(n) = f(n -
1) + f(n - 2) for n > 1.
So it goes like this: 0, 1, 1, 2, 3, 5, 8, 13, etc.
Think about how you would implement this recursively. Hint: look at the
above definition.
Write it. See how slow it is? Find out why. Hint: use printf.
Now think about how you could make it a lot faster. Hint: think about
arrays.
Now see if you can avoid the need for an array by writing this iteratively
instead of recursively.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
.
- Follow-Ups:
- Re: Fibonnaci
- From: Jordan Abel
- Re: Fibonnaci
- From: Suman
- Re: Fibonnaci
- References:
- Fibonnaci
- From: MARQUITOS51
- Fibonnaci
- Prev by Date: Re: Fibonnaci
- Next by Date: Re: declaration Q
- Previous by thread: Re: Fibonnaci
- Next by thread: Re: Fibonnaci
- Index(es):
Relevant Pages
|