#include<iostream>
using namespace std;
int Fib(int n)
{
if(n <= 1) return n;
return Fib(n - 1) + Fib(n - 2);
}
int main()
{
int n;
cout << "Give me an n: ";
cin >> n;
int result = Fib(n);
cout << result;
return 0;
}
#include<iostream>
using namespace std;
int Fib(int n)
{
if(n <= 1) return n;
int F, F1 = 0, F2 = 1;
for(int i = 2; i <= n; i++)
{
F = F1 + F2;
F1 = F2;
F2 = F;
}
return F;
}
int main()
{
int n;
cout << "Give me an n: ";
cin >> n;
int result = Fib(n);
cout << result;
return 0;
}
因篇幅问题不能全部显示,请点此查看更多更全内容