当前位置:网站首页>[C language series] - a recursive topic
[C language series] - a recursive topic
2022-07-29 05:35:00 【Gancheng なつき】
꧁ Hello, everybody ! It is a great honor to have your visit , Let's have a long way to go in programming !꧂
* Blog column :【C All living things 】*
Introduction to this article : Simply tear a recursive topic by hand !
Get to know the author : Aspire to be a great programmer , Xiaobai, who is currently a sophomore in College .
Inspirational terms : The tediousness of programming , Let's study together and become interesting !
Text begins
List of articles
Preface
In a scene yesterday C In the preliminary language examination , Fortunately, I came across a problem about recursion , The problem I couldn't do at that time , But with years of guessing experience , Very lucky to guess the right answer !

subject
After the following procedure is executed , What is the result of the output ?
#include<stdio.h>
int cnt = 0;
int fib(int n)
{
cnt++;
if (n == 0)
return 1;
else if (n == 1)
return 2;
else
return fib(n - 1) + fib(n - 2);
}
int main()
{
fib(8);
printf("%d", cnt);
return 0;
}
Ideas
To write this problem, you must understand the concept and usage of recursive functions !
Now let's analyze this problem :
1. Global variables are defined cnt Used to count , Every time you call a function ,cnt Meeting ++ once , The main function passes a 8 Get into fib() function ;
After analysis, this problem actually requires to find out that when the transmission parameter is 8 when , Called fib() The number of functions !
2. Drawing pictures is more conducive to solving problems !
Graphic process

Let's run it to see if 67 Time !

Conclusion
well ! This is the end of my sharing today , If you think it helps , You can pay attention to bloggers ! Bloggers will update regularly !
边栏推荐
- ClickHouse学习(五)集群操作
- 使用微信小程序扫码登录系统PC端web的功能
- ANSI C type qualifier
- 实现简单的数据库查询(不完整)
- 省市区三级联动(简单又完美)
- Alibaba cloud Zhang Xintao: heterogeneous computing provides surging power for the digital economy
- With cloud simulation platform, Shichuang technology supports the upgrading of "China smart manufacturing"
- uniapp组件之tab选项卡滑动切换
- JS deep copy - Notes
- Allocate memory: malloc() and free()
猜你喜欢
随机推荐
公众号不支持markdown格式文件编写怎么办?
Day 5
Clickhouse learning (VI) grammar optimization
【TypeScript】深入学习TypeScript函数
shell基本操作(上)
抽象类与接口
Cryengine5 shader debugging
shell基本操作(下)
无重复字符的最长字串
Occt learning 001 - Introduction
Clickhouse learning (XI) clickhouseapi operation
Detailed explanation of GPIO input and output
Cryengine3 debugging shader method
link与@import导入外部样式的区别
Day 1
表格与表单相关知识点总结
省市区三级联动(简单又完美)
ClickHouse学习(六)语法优化
【剑指offer】— 详解库函数atoi以及模拟实现atoi函数
实现简单的数据库查询(不完整)









