fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int n;
  5.  
  6. void Fib(int x)
  7. {
  8. int f, f1, f2;
  9. f1=1; f2=0;
  10. if (x==0) {cout<<f2<<"\t";}
  11. if(x==1) {cout<<f2<<"\t"<<f1<<"\t";}
  12. else {
  13. cout<<f2<<"\t"<<f1<<"\t";
  14. for(int i=3; i<=x; i++)
  15. {
  16. f= f1+f2;
  17. cout<<f<<"\t";
  18. f2=f1;
  19. f1=f;
  20. }
  21. }
  22.  
  23. }
  24.  
  25. int main() {
  26.  
  27. cin>>n;
  28. while(n<0)
  29. {
  30. cin>>n;
  31. }
  32.  
  33. Fib(n);
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5272KB
stdin
-1
7
stdout
0	1	1	2	3	5	8