一对兔子从出生后第三个月起,每个月都生一对兔子,小兔子长大到第三个月后,每个月又生一对兔子,假如兔子都不死,请问第一个月出生的一对兔子至少需要反演到第几个月时,兔子总数才能够达到n对,输入一个不超过10000的正整数n输出兔子总数达n对时最少需要的月数
参考答案1:
关注博主不迷路,博主带你码代码。
#include <stdio.h>int main(){ int n; int month = 1; scanf("%d", &n); if (n == 1) month = 1; else { int a = 1; int b = 1; int c = 1; month = 2; while (c < n) { c = a + b; a = b; b = c; month++; } } printf("%d", month); return 0;}
参考答案2:
版权声明
本文为[CSDN问答]所创,转载请带上原文链接,感谢
https://ask.csdn.net/questions/7579467