当前位置:网站首页>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;
}
边栏推荐
- Uibutton status exploration and customization
- “人生若只如初见”——RISC-V
- 数据库多表链接的查询方式
- 四元数---基本概念(转载)
- Statistics, 8th Edition, Jia Junping, Chapter 11 summary of knowledge points of univariate linear regression and answers to exercises after class
- On the idea of vulnerability discovery
- 《统计学》第八版贾俊平第十二章多元线性回归知识点总结及课后习题答案
- Get started with Matplotlib drawing
- Statistics 8th Edition Jia Junping Chapter 3 after class exercises and answer summary
- 关于交换a和b的值的四种方法
猜你喜欢

Matplotlib绘图快速入门

Solutions to common problems in database development such as MySQL
![[paper reproduction] cyclegan (based on pytorch framework) {unfinished}](/img/16/43d8929d1a37c1c68e959d5854e18c.jpg)
[paper reproduction] cyclegan (based on pytorch framework) {unfinished}

《统计学》第八版贾俊平第五章概率与概率分布

Attack and defense world misc practice area (GIF lift table ext3)

Get started with Matplotlib drawing

《统计学》第八版贾俊平第六章统计量及抽样分布知识点总结及课后习题答案

Lintcode logo queries the two nearest saplings

Network technology related topics

《统计学》第八版贾俊平第十二章多元线性回归知识点总结及课后习题答案
随机推荐
Function: find the maximum common divisor and the minimum common multiple of two positive numbers
5分钟掌握机器学习鸢尾花逻辑回归分类
《统计学》第八版贾俊平第十一章一元线性回归知识点总结及课后习题答案
This article explains in detail how mockmvc is used in practical work
My first blog
MySQL interview questions (4)
Hcip -- MPLS experiment
[pointer] counts the number of times one string appears in another string
[pointer] octal to decimal
Es full text index
What language should I learn from zero foundation. Suggestions
Summary of thread implementation
Get started with Matplotlib drawing
Flash implements forced login
C language learning summary (I) (under update)
函数:求1-1/2+1/3-1/4+1/5-1/6+1/7-…+1/n
线程的实现方式总结
Functions: Finding Roots of equations
【指针】八进制转换为十进制
函数:计算字符串中大写字母的个数