day 5 兔子产子

 

1.找出递推关系month[n]=month[n-3]+month[n-1];

2.依据已知条件得到month[0],month[1],month[2];

3.根据递推得到month[29];

 

 

 

#include<iostream>

 

using namespace std;

 

int main(){
int month[30];
month[0]=month[1]=2,month[2]=4;
for(int i=3;i<30;i++){
month[i]=month[i-1]+month[i-2];
}
for(int i=0;i<30;i++)printf("第%d个月的兔子有%d只\n",i+1,month[i]);
return 0;
}

 

 

 

 

posted @ 2023-04-14 20:49  The-rich  阅读(8)  评论(0编辑  收藏  举报