Description
第一年,只有一头小母牛(0岁),它从第四年(3岁)开始,每年都生一头小母牛(一年只生一头),而且,所有的小母牛也都会在第四年开始生育……..假设所有的母牛都不会死,请问,第n年,此牛群共有多少母牛?
Input
键盘输入一个整数n
Output
Sample Input
1
Sample Output
1
1 1 1 2 3 4 6 9 13 19 28 41
CODE
#include <stdio.h>
int main()
{
int n,i;
int a=1,b=1,c=1,ans;
scanf("%d",&n);
if(n<=3)
printf("1\n");
else
{
for(i=4;i<=n;i++)
{
ans=a+c;
a=b;
b=c;
c=ans;
}
printf("%d\n",ans);
}
return 0;
}