兔子问题 有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第四个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?


有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第四个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?

#include<iostream>

#include<cstdio>
using namespace std;
int main()
{
int a=1,b=1,c,k,e=1;
scanf("%d",&k);
if(k<=2)
cout<<1<<endl;
else 
{   printf("%-11d%-11d",e,e);
   for (int i=1;i<=k-2;i++)
{
c=a+b;
a=b;
b=c;

printf("%-10d ",c);
if(i%4==2)
cout<<" "<<endl;
}
  
}
return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42552468/article/details/80849484