当前位置:网站首页>浙大版《C语言程序设计实验与习题指导(第3版)》题目集
浙大版《C语言程序设计实验与习题指导(第3版)》题目集
2022-07-06 09:23:00 【无二三事】
实验4-1-10 兔子繁衍问题
分数 15
全屏浏览题目
切换布局
作者 徐镜春
单位 浙江大学
一对兔子,从出生后第3个月起每个月都生一对兔子。小兔子长到第3个月后每个月又生一对兔子。假如兔子都不死,请问第1个月出生的一对兔子,至少需要繁衍到第几个月时兔子总数才可以达到N对?
输入格式:
输入在一行中给出一个不超过10000的正整数N。
输出格式:
在一行中输出兔子总数达到N最少需要的月数。
输入样例:
30
输出样例:
9
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
代码实现:
# include <stdio.h>
main() {
int N;
scanf("%d",&N);// 1,1,2,3满足斐波那契数列
int a = 1,b = 1,max = 1,temp,month = 1;
if (N == 1) {
printf("%d",month);
}else {
month = 2;
while(max < N) {
temp = a;
a += b;
b = temp;
max = (a >= b) ? a : b;
month += 1;
}
printf("%d",month);
}
return 0;
}
边栏推荐
- Ucos-iii learning records (11) - task management
- MySQL interview questions (4)
- 中间件漏洞复现—apache
- 7-7 7003 combination lock (PTA program design)
- Hackmyvm target series (2) -warrior
- Intranet information collection of Intranet penetration (4)
- Callback function ----------- callback
- JDBC transactions, batch processing, and connection pooling (super detailed)
- Record an API interface SQL injection practice
- 记一次api接口SQL注入实战
猜你喜欢

《统计学》第八版贾俊平第九章分类数据分析知识点总结及课后习题答案

《统计学》第八版贾俊平第三章课后习题及答案总结

Hackmyvm Target Series (3) - vues

Strengthen basic learning records
![[paper reproduction] cyclegan (based on pytorch framework) {unfinished}](/img/16/43d8929d1a37c1c68e959d5854e18c.jpg)
[paper reproduction] cyclegan (based on pytorch framework) {unfinished}

图书管理系统

7-5 staircase upgrade (PTA program design)

Sqqyw (indifferent dot icon system) vulnerability recurrence and 74cms vulnerability recurrence

Mixlab unbounded community white paper officially released

Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
随机推荐
Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
Harmonyos JS demo application development
Package bedding of components
Intranet information collection of Intranet penetration (2)
7-5 staircase upgrade (PTA program design)
强化學習基礎記錄
Tencent map circle
JDBC read this article is enough
Force deduction 152 question multiplier maximum subarray
Solutions to common problems in database development such as MySQL
[err] 1055 - expression 1 of order by clause is not in group by clause MySQL
7-14 error ticket (PTA program design)
Detailed explanation of network foundation routing
Sqqyw (indifferent dot icon system) vulnerability recurrence and 74cms vulnerability recurrence
Intranet information collection of Intranet penetration (5)
[paper reproduction] cyclegan (based on pytorch framework) {unfinished}
JDBC看这篇就够了
《统计学》第八版贾俊平第十四章指数知识点总结及课后习题答案
Mixlab unbounded community white paper officially released
《统计学》第八版贾俊平第七章知识点总结及课后习题答案