fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int fib(int n) {
  5. if (n == 0) {
  6. return 0;
  7. }
  8. if (n == 1) {
  9. return 1;
  10. }
  11.  
  12. return fib(n-1) + fib(n-2);
  13. }
  14.  
  15. int main() {
  16. ios_base::sync_with_stdio(0);
  17. cin.tie(0);
  18.  
  19. int n;
  20. cin >> n;
  21.  
  22. cout << fib(n);
  23.  
  24. return 0;
  25. }
  26.  
Success #stdin #stdout 0.01s 5276KB
stdin
5
stdout
5