Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. int f0 = 0, f1 = 1, f2 = 1, fn = 0;
  8.  
  9. int n;
  10.  
  11. cin >> n;
  12.  
  13. switch (n) {
  14. case 0:
  15. cout << f0;
  16. break;
  17. case 1:
  18. cout << f1;
  19. break;
  20. case 2:
  21. cout << f2;
  22. break;
  23. default:
  24. for (int i = 0; i < n - 2; ++i)
  25. {
  26. fn = f0 + f2;
  27. f0 = f1;
  28. f1 = f2;
  29. f2 = fn;
  30. }
  31. cout << fn;
  32. break;
  33. }
  34.  
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement