#include<iostream>
using namespace std;
int main()
{
long long f0 = 0, f1 = 1, f2;
int n;
cin >> n;
if (n == 0) f1 = f0;
else if (n != 1) for (int i = n; i >= 2; i--)
f2 = f0 + f1;
f0 = f1;
f1 = f2;
}
cout << f1;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include<iostream>
using namespace std;
int main()
{
long long f0 = 0, f1 = 1, f2;
int n;
cin >> n;
if (n == 0) f1 = f0;
else if (n != 1) for (int i = n; i >= 2; i--)
{
f2 = f0 + f1;
f0 = f1;
f1 = f2;
}
cout << f1;
}