当前位置:网站首页>Exercise 10-6 recursively find Fabonacci sequence
Exercise 10-6 recursively find Fabonacci sequence
2022-07-03 14:09:00 【ᯤ⁹ᴳ⁺ ·】
exercises 10-6 Recursive search Fabonacci The sequence (10 branch )
This problem requires the realization of Fabonacci A function of a sequence item .Fabonacci The definition of sequence is as follows :
f(n)=f(n−2)+f(n−1) (n≥2), among f(0)=0,f(1)=1.
Function interface definition :
int f( int n );
function f
Should return to section n
individual Fabonacci Count . The title guarantees that the input and output are in the long integer range . It is suggested to use recursion to realize .
Sample referee test procedure :
#include <stdio.h>
int f( int n );
int main()
{
int n;
scanf("%d", &n);
printf("%d\n", f(n));
return 0;
}
/* Your code will be embedded here */
sample input :
6
sample output :
8
int f( int n ){
int number;
if(n==0){
number=0;
}else if(n==1){
number=1;
}else{
number=f(n-1)+f(n-2);
}
return number;
}
边栏推荐
- Qt学习24 布局管理器(三)
- Metal organic framework (MOFs) antitumor drug carrier | pcn-223 loaded with metronidazole | uio-66 loaded with ciprofloxacin hydrochloride( JVM runtime data area
- Implementation of Muduo accept connection, disconnection and sending data
- Reflection -- basic usage
- How to bold text in AI
- page owner特性浅析
- JS matrix zero
- 7-9 find a small ball with a balance
- 28: Chapter 3: develop Passport Service: 11: define attributes in the configuration file, and then obtain them in the code;
猜你喜欢
Qt学习18 登录对话框实例分析
Mysql:insert date:sql error [1292] [22001]: data truncation: incorrect date value:
Rasp implementation of PHP
[Jilin University] information sharing of postgraduate entrance examination and re examination
QT learning 20 standard dialog box in QT (middle)
GoLand 2021.1.1: configure the multi line display of the tab of the open file
Installation impression notes
GoLand 2021.2 configure go (go1.17.6)
Dlopen() implements dynamic loading of third-party libraries
金属有机骨架MOFs装载非甾体类抗炎药物|ZIF-8包裹普鲁士蓝负载槲皮素(制备方法)
随机推荐
消息订阅与发布
Scroll detection, so that the content in the lower right corner is not displayed at the top of the page, but is displayed as the mouse slides
C language standard IO function sorting
Onmenusharetimeline custom shared content is invalid, and the title and icon are not displayed
3D vision - 2 Introduction to pose estimation - openpose includes installation, compilation and use (single frame, real-time video)
Cross linked cyclodextrin metal organic framework loaded methotrexate slow-release particles | metal organic porous material uio-66 loaded with flavonoid glycosides | Qiyue
Go: send the get request and parse the return JSON (go1.16.4)
Multi person collaborative data annotation based on Baidu brain easydata from scratch
Uniapp skills - scrolling components -1
QT learning 20 standard dialog box in QT (middle)
Solve MySQL 1045 access denied for user 'root' @ 'localhost' (using password: yes)
怎样删除对象的某个属性或⽅法
Rasp implementation of PHP
Interface for querying IP home
Redis: operation command of string type data
28: Chapter 3: develop Passport Service: 11: define attributes in the configuration file, and then obtain them in the code;
交联环糊精金属有机骨架负载甲氨蝶呤缓释微粒|金属-有机多孔材料UiO-66负载黄酮苷类药物|齐岳
Go 1.16.4: manage third-party libraries with Mod
UiO-66-COOH装载苯达莫司汀|羟基磷灰石( HA) 包裹MIL-53(Fe)纳米粒子|装载黄芩苷锰基金属有机骨架材料
金属有机骨架MOFs装载非甾体类抗炎药物|ZIF-8包裹普鲁士蓝负载槲皮素(制备方法)