fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3. int fib_n(int n);
  4. int main() {
  5. cout<<"input N"<<endl;
  6. int n;
  7. cin>>n;
  8. cout<<"F:\t"<<fib_n(n)<<endl;
  9. return 0;
  10. }
  11.  
  12. int fib_n(int n)
  13. {
  14. if (n <= 2) return 1;
  15.  
  16. int x = 1;
  17. int y = 1;
  18. int ans = 0;
  19. for (int i = 2; i < n; i++)
  20. {
  21. ans = x + y;
  22. x = y;
  23. y = ans;
  24. }
  25. return ans;
  26. }
Success #stdin #stdout 0s 3144KB
stdin
2
stdout
input N
F:	1