当前位置:网站首页>浙大版《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;
}
边栏推荐
猜你喜欢

Based on authorized access, cross host, and permission allocation under sqlserver

Intel oneapi - opening a new era of heterogeneity

Record once, modify password logic vulnerability actual combat

List and data frame of R language experiment III

Solutions to common problems in database development such as MySQL

《统计学》第八版贾俊平第十一章一元线性回归知识点总结及课后习题答案

网络层—简单的arp断网

Only 40% of the articles are original? Here comes the modification method

xray與burp聯動 挖掘

Xray and burp linkage mining
随机推荐
Intel oneapi - opening a new era of heterogeneity
《统计学》第八版贾俊平第十一章一元线性回归知识点总结及课后习题答案
"Gold, silver and four" job hopping needs to be cautious. Can an article solve the interview?
Callback function ----------- callback
Binary search tree concept
Sword finger offer 23 - print binary tree from top to bottom
DVWA (5th week)
Hackmyvm target series (7) -tron
Strengthen basic learning records
《统计学》第八版贾俊平第十三章时间序列分析和预测知识点总结及课后习题答案
Experiment five categories and objects
小程序web抓包-fiddler
[issue 18] share a Netease go experience
Detailed explanation of three ways of HTTP caching
网络基础详解
Force deduction 152 question multiplier maximum subarray
JDBC read this article is enough
Middleware vulnerability recurrence Apache
中间件漏洞复现—apache
Intranet information collection of Intranet penetration (5)