当前位置:网站首页>Zhejiang University Edition "C language programming experiment and exercise guide (3rd Edition)" topic set
Zhejiang University Edition "C language programming experiment and exercise guide (3rd Edition)" topic set
2022-07-06 14:42:00 【No two or three things】
experiment 4-1-10 The problem of rabbit reproduction
fraction 15
Full screen browsing topics
Switch layout
author Xu Jingchun
Company Zhejiang University
A couple of Rabbits , From the day after birth 3 A couple of rabbits are born every month from . The little rabbit grows to the third place 3 Two months later, a couple of rabbits were born every month . If the rabbits don't die , May I ask 1 A pair of rabbits born six months ago , It will take at least a few months for the total number of rabbits to reach N Yes ?
Input format :
The input gives no more than 10000 The positive integer N.
Output format :
Output the total number of rabbits in one line to N Minimum number of months required .
sample input :
30
sample output :
9
Code length limit
16 KB
The time limit
400 ms
Memory limit
64 MB
Code implementation :
# include <stdio.h>
main() {
int N;
scanf("%d",&N);// 1,1,2,3 Satisfy Fibonacci sequence
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;
}
边栏推荐
- Statistics, 8th Edition, Jia Junping, Chapter VIII, summary of knowledge points of hypothesis test and answers to exercises after class
- c语言学习总结(上)(更新中)
- Quaternion -- basic concepts (Reprint)
- [pointer] delete all spaces in the string s
- Pointers: maximum, minimum, and average
- 《统计学》第八版贾俊平第八章假设检验知识点总结及课后习题答案
- JDBC read this article is enough
- Function: find the root of the equation by Newton iterative method
- Harmonyos application development -- address book management system telmanagesys based on listcontainer [phonebook][api v6]
- Intranet information collection of Intranet penetration (3)
猜你喜欢
线程的实现方式总结
四元数---基本概念(转载)
High concurrency programming series: 6 steps of JVM performance tuning and detailed explanation of key tuning parameters
What is an index in MySQL? What kinds of indexes are commonly used? Under what circumstances will the index fail?
Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
Data mining - a discussion on sample imbalance in classification problems
Get started with Matplotlib drawing
Intel oneapi - opening a new era of heterogeneity
JDBC看这篇就够了
. Net6: develop modern 3D industrial software based on WPF (2)
随机推荐
What language should I learn from zero foundation. Suggestions
指针--剔除字符串中的所有数字
MySQL interview questions (4)
c语言学习总结(上)(更新中)
Always of SystemVerilog usage_ comb 、always_ iff
“人生若只如初见”——RISC-V
《统计学》第八版贾俊平第一章课后习题及答案总结
数字电路基础(三)编码器和译码器
函数:求方程的根
Circular queue (C language)
《统计学》第八版贾俊平第六章统计量及抽样分布知识点总结及课后习题答案
关于超星脚本出现乱码问题
5分钟掌握机器学习鸢尾花逻辑回归分类
On the idea of vulnerability discovery
Sentinel overall workflow
The most popular colloquial system explains the base of numbers
Fundamentals of digital circuit (IV) data distributor, data selector and numerical comparator
Function: calculates the number of uppercase letters in a string
【指针】八进制转换为十进制
Proceedingjoinpoint API use