Thread: fibonacci
View Single Post
Join Date: Jun 2006
Posts: 1,169
Reputation: Duki has a spectacular aura about Duki has a spectacular aura about Duki has a spectacular aura about 
Solved Threads: 9
Duki's Avatar
Duki Duki is offline Offline
Veteran Poster

fibonacci

 
0
  #1
Oct 24th, 2007
Hey guys,

I'm supposed to write a program that will calculate the Nth fibonacci number, without using recursion.

I have the recursion problem written already, but am having a hard time doing the iterative one.

here's my recursion function:

  1. int fib ( int n )
  2. {
  3. if ( n <= 1 )
  4. return 1 ;
  5. else
  6. return ( fib ( n - 1 ) + ( fib ( n - 2 ) ) ) ;
  7. }

any help with getting me started on the iterative one?
It is practically impossible to teach good programming style to students that have had prior exposure to Basic; as potential programmers they are mentally mutilated beyond hope of regeneration.

-Edsger Dijkstra
Reply With Quote