fork(2) download
  1. #include <iomanip>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int main(void)
  6. {
  7. int n, count, a = 0, b = 1, fibsequence;
  8. cout << "Which Fibonacci number do you want to find? ";
  9. cin >> n;
  10. /*if (n == 0)
  11.   cout << "0";
  12.   else if (n>0)
  13.   cout << "0, "; */
  14. // cout << "The number entered must be greater than or equal to zero";
  15. for (int count = 0 ; count < n ; count++ )
  16. {
  17. if ( count <= 1 )
  18. fibsequence = count;
  19. else
  20. {
  21. fibsequence = a + b;
  22. a = b;
  23. b = fibsequence;
  24. }
  25. cout << fibsequence <<", ";
  26. }
  27. cout << "...";
  28. return 0;
  29. }
Success #stdin #stdout 0.01s 2728KB
stdin
Standard input is empty
stdout
Which Fibonacci number do you want to find? ...