fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. long int fib2(int n) {
  5. int a = 1;
  6. int b = 1;
  7. for (int i = 3; i <= n; i++){
  8. int pom = a;
  9. a = b;
  10. b = pom + b;
  11. }
  12. return b;
  13. }
  14. int main() {
  15. cout << fib2(4) << endl;
  16. cout << fib2(11) << endl;
  17. return 0;
  18. }
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
3
89