fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // dla n
  5. // fibonacci(n) - n-ty wyraz ciagu
  6.  
  7. int main() {
  8.  
  9. int n, a=1, b=1, c;
  10. cin >> n;
  11.  
  12. if (n==1 || n==2)
  13. cout << 1 << endl;
  14. else
  15. {
  16. for (int i=3; i<=n; i++)
  17. {
  18. c=a+b;
  19. a=b;
  20. b=c;
  21. }
  22. cout << c << endl;
  23. }
  24. return 0;
  25. }
Success #stdin #stdout 0.01s 5316KB
stdin
49
stdout
-811192543