当前位置:网站首页>Zzuli:1055 rabbit reproduction
Zzuli:1055 rabbit reproduction
2022-07-03 14:34:00 【Snake_____】
Title Description
This is an interesting classical mathematical problem , Famous Italian mathematician Fibonacci A question was raised : There's 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 . According to this rule , Suppose no rabbits died , In the first month, there was a couple of newborn rabbits , Ask No n How many pairs of rabbits in a month ?
Input
Enter the number of months n(1<=n<=44).
Output
Output No n How many pairs of rabbits in a month .
The sample input Copy
3
Sample output Copy
2
Tips
This topic is a classic introduction to recursion : use f(n) It means the first one n Number of rabbits in months , be : f(n) = f(n-1) + Number of rabbits born this month and , Number of rabbits born this month = f(n-2) ( Because every rabbit that existed last month , A new rabbit will be born this month ) therefore ,f(n) = f(n-1) + f(n-2) That's the famous one fabinacci The sequence , The latter is equal to the sum of the first two : 1 1 2 3 5 8.....
#include <stdio.h>
int main()
{
int i,n,a=1,b=1,c;
scanf("%d",&n);
if(n==1)
{
printf("%d",a);
}
else
{
for(i=2;i<n;i++)
{
c=a;
a=a+b;
b=c;
}
printf("%d",a);
}
return 0;
}边栏推荐
猜你喜欢

Puzzle (016.4) domino effect

基因家族特征分析 - 染色体定位分析

修改数据库中的记录为什么报这个错

Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions

Analysis of gene family characteristics - chromosome location analysis

Tonybot humanoid robot checks the port and corresponds to port 0701

Leetcode (4) - - trouver la médiane de deux tableaux ordonnés positifs

剑指 Offer 28. 对称的二叉树

puzzle(016.4)多米诺效应

天图投资冲刺港股:资产管理规模249亿 投了小红书与奈雪
随机推荐
Zzuli:1042 sum of sequence 3
7-10 stack of hats (25 points) (C language solution)
Tonybot Humanoïde Robot Infrared Remote play 0630
7-6 mixed type data format input
Frequently asked questions: PHP LDAP_ add(): Add: Undefined attribute type in
7-20 print 99 formula table (format output)
表单文本框的使用(一) 选择文本
洛谷P5194 [USACO05DEC]Scales S 题解
puzzle(016.4)多米诺效应
Plane vector addition
Zzuli:1041 sum of sequence 2
Tonybot humanoid robot starts for the first time 0630
分布式事务(Seata) 四大模式详解
ShowMeBug入驻腾讯会议,开启专业级技术面试时代
Find the sum of the elements of each row of the matrix
Concat and concat_ Ws() differences and groups_ Use of concat() and repeat() functions
adc128s022 ADC verilog设计实现
超简单手机地图开发
Zzuli:1040 sum of sequence 1
7-17 crawling worms (break exercise)