fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int fibonacci(int n) {
  5. int f0 = 0, f1 = 1, fibo = 0;
  6.  
  7. for (int i = 0; i < n; i++) {
  8. fibo = f0 + f1;
  9. f0 = f1;
  10. f1 = fibo;
  11. }
  12. return f0;
  13. }
  14.  
  15. int main() {
  16. int n;
  17. cin >> n;
  18. cout << fibonacci(n) << endl;
  19. return 0;
  20. }
Success #stdin #stdout 0.01s 5288KB
stdin
3

stdout
2