fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // zdefiniuj funkcję
  5. long int fib2(int n) {
  6. if (n == 0)return 0;
  7. if (n == 1)return 1;
  8.  
  9. long int a = 0;
  10. long int b = 1;
  11. long int c;
  12.  
  13. for(int i = 2; i <= n; i++) {
  14. c = a + b;
  15. a = b;
  16. b = c;
  17. }
  18.  
  19. return b;
  20.  
  21. }
  22. int main() {
  23. cout << fib2(4) << endl;
  24. cout << fib2(11) << endl;
  25. return 0;
  26. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
3
89