Re: Fibonnaci



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)
.



Relevant Pages

  • Re: Fibonnaci
    ... Hint: use printf. ... >> arrays. ... recursion-based solution to a memoized recursion, ...
    (comp.lang.c)
  • Re: Using representation clauses in networking software
    ... Sounds like a lost optimization opportunity with absolutely no overall ... gain. ... Hint: it most likely does not make much difference for individual ... but things get more interesting with arrays - the longer the ...
    (comp.lang.ada)
  • Re: vector-push-extend
    ... (or have a look at adjustable arrays). ... That works of course because size is the same; but your hint to ... It's funny though that SBCL seems ...
    (comp.lang.lisp)
  • Re: Which company is MFR90073? (Manufacturer of TTL chips in 1981)...
    ... 90073 is a CAGE code for CMC, probably a mfr or dist. ... Thanks for this hint. ... transistors driving the hinhibit lines. ... either transistor arrays, ...
    (sci.electronics.components)