Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int f0 = 0, f1 = 1, f2 = 1, fn = 0;
- int n;
- cin >> n;
- switch (n) {
- case 0:
- cout << f0;
- break;
- case 1:
- cout << f1;
- break;
- case 2:
- cout << f2;
- break;
- default:
- for (int i = 0; i < n - 2; ++i)
- {
- fn = f0 + f2;
- f0 = f1;
- f1 = f2;
- f2 = fn;
- }
- cout << fn;
- break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement