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

Re: fibonacci

 
0
  #2
Oct 24th, 2007
Nevermind, I got it working. Didn't think to use an array; well I thought about it, but didn't think it would make the problem easier. Here's my fibonacci sequence, written iteratively.

  1. #include <iostream>
  2. using namespace std ;
  3.  
  4. int main ( )
  5. {
  6. int fibArray[25] ; //max fib number
  7. fibArray[0] = 1 ;
  8. fibArray[1] = 1 ;
  9.  
  10. for ( int i = 2 ; i < 25 ; i ++ )
  11. fibArray[ i ] = fibArray[ i - 1 ] + fibArray[ i - 2 ] ;
  12.  
  13. cout << fibArray[4] << "\t" << fibArray[7] << "\t" << fibArray[24] << endl ;
  14.  
  15. return 0 ;
  16. }
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