问题描述
有一对兔子,从出生后的第3个月起每个月都生一对兔子。小兔子长到第3个月后每个月又生一对兔子,假设所有的兔子都不死,问30个月内每个月的兔子总数为多少?
代码如下
#include<iostream>
using namespace std;
int main()
{
long int fib1 = 1,fib2=1;
long fib;
cout << fib1 << " " << fib2 << " ";
for (int i = 3; i < 30; i++) {
fib = fib1 + fib2;
cout << fib << " ";
if (i % 4 == 0) {
cout << endl;
}
fib2= fib1;
fib1 = fib;
}
}
标签:每个,产子,int,long,问题,兔子,一对
From: https://www.cnblogs.com/drip3775/p/17353628.html