养兔子
Time Limit: 1000MS Memory Limit: 65536KB
Problem Description
一对成熟的兔子每天能且只能产下一对小兔子,每次都生一公一母,每只小兔子的成熟期是一天。某人领养了一对小兔子,一公一母,请问第N天以后,他将会得到多少对兔子。
Input
测试数据包括多组,每组一行,为整数n(1≤n≤90)。
输入以0结束。
输入以0结束。
Output
对应输出第n天有几对兔子(假设没有兔子死亡现象,而且是一夫一妻制)。
Example Input
1
2
0
Example Output
1
2
#include<stdio.h>
int main()
{
int n;
long long int f[100];
while(scanf("%d",&n)&&n!=0)
{
f[1]=1;
f[2]=2;
for(int i=3;i<=n;i++)
{
f[i]=f[i-1]+f[i-2];
}
printf("%lld\n",f[n]);
}
return 0;
}