代码的简单实现:
#include
using namespace std;
long long int f(int n){long long int a,a1=1,a2=2,a3=3,i;if(n==1)a=1;else if(n==2)a=1;else {a=f(n-1)+f(n-2);}return a;
}
int main()
{
int n;
while(~scanf("%d",&n)&&n)
{printf("%lld\n",f(n+4));
}
return 0;
}
进阶的代码实现:
#include
using namespace std;
int main()
{int n,i;while(~scanf("%d",&n)){int a[n];a[0]&#61;5;a[1]&#61;8;for(i&#61;2;i<n;i&#43;&#43;){a[i]&#61;a[i-1]&#43;a[i-2];}printf("%d\n",a[n-1]);}return 0;
}