fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int fib(int n) {
  5. int a = 1;
  6. int b = 1;
  7. int c;
  8. for (int i = 2; i <= n; i++) {
  9. c = a + b;
  10. a = b;
  11. b = c;
  12. }
  13. return c;
  14. }
  15.  
  16. int main() {
  17. int n;
  18. cin >> n;
  19.  
  20. cout << fib(n) << endl;
  21. return 0;
  22. }
Success #stdin #stdout 0.01s 5320KB
stdin
40
stdout
165580141