C++ Fibonacci program help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2006
Posts: 6
Reputation: level007 is an unknown quantity at this point 
Solved Threads: 0
level007's Avatar
level007 level007 is offline Offline
Newbie Poster

Re: C++ Fibonacci program help

 
0
  #11
Jan 1st, 2008
  1. #include <iostream.h>
  2. #include <stdlib.h>
  3.  
  4. int fibonacci()
  5. {
  6. unsigned long fib;
  7. cout << "Please input a number of fibonacci numbers which will be displayed: ";
  8. cin >> fib;
  9. unsigned long a = 1;
  10. unsigned long b = 1;
  11. unsigned long temp;
  12. for (int count1 = 0; fib != count1; count1 ++)
  13. {
  14. cout << a << " is the " << count1 + 1 << "th number\n";
  15. temp = b;
  16. b += a;
  17. a = temp;
  18. }
  19. return 0;
  20. }
  21.  
  22. int main()
  23. {
  24. fibonacci();
  25. cout << endl;
  26. system("PAUSE");
  27. return 0;
  28. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: C++ Fibonacci program help

 
0
  #12
Jan 1st, 2008
Please check the date on the threads before you post.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 464
Reputation: invisal is a jewel in the rough invisal is a jewel in the rough invisal is a jewel in the rough 
Solved Threads: 49
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: C++ Fibonacci program help

 
0
  #13
Jan 1st, 2008
Originally Posted by Kazastankas View Post
Wouldn't that trap high at 1 and low at 0? Perhaps 1, 1 are what you meant as starting vars.
No, and it works perfectly. For example: the 10th of fibonacci:

high = 1   ; low = 0
------------------------
high = 1   ; low = 1
high = 2   ; low = 1
high = 3   ; low = 2
high = 5   ; low = 3
high = 8   ; low = 5
high = 13  ; low = 8
high = 21  ; low = 13
high = 34  ; low = 21
high = 55  ; low = 34
high = 89  ; low = 55
Last edited by invisal; Jan 1st, 2008 at 4:26 pm.
Yesterday is a history, tomorrow is a mystery, today is a gift.
Behind every smile is a tear.
Visal .In
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 464
Reputation: invisal is a jewel in the rough invisal is a jewel in the rough invisal is a jewel in the rough 
Solved Threads: 49
invisal's Avatar
invisal invisal is offline Offline
Posting Pro in Training

Re: C++ Fibonacci program help

 
0
  #14
Jan 1st, 2008
Oh crap, I got fool Next time, I will check the date. (mad)
Yesterday is a history, tomorrow is a mystery, today is a gift.
Behind every smile is a tear.
Visal .In
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC