兔子繁殖问题(斐波拉契)

如果1对兔子每月能生1对小兔子,而每对小兔在它出生后的第3个月就可以生1对小兔子,如果从1对初生的小兔子开始,1年后能
繁殖多少兔子

include

include

using namespace std;

int main(){
int month[12];
month[0] = 1;
month[1] = 1;
for(int i=2;i<12;i++){
month[i] = month[i-1] + month[i-2];
}
for(int i=0;i<12;i++){
cout<<"在第"<<i<<"个月兔子有"<<setw(4)<<month[i]<<setw(4)<<"只"<<endl;
}
return 0;
}

猜你喜欢

转载自www.cnblogs.com/hglibin/p/8961755.html