当前位置:网站首页>[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 !
边栏推荐
- 微信小程序视频上传组件直接上传至阿里云OSS
- Cryengine3 debugging shader method
- Solution: find the position of the first and last element in a sorted array (personal notes)
- paddle.fluild常量计算报错‘NoneType‘ object has no attribute ‘get_fetch_list‘
- href与src的区别
- Introduction to array learning simple question sum of two numbers
- Question swiping Madness - leetcode's sword finger offer58 - ii Detailed explanation of left rotation string
- 力扣994:腐烂的橘子(BFS)
- ClickHouse学习(七)表查询优化
- JS deep copy - Notes
猜你喜欢

One dimensional array exercise

Clickhouse learning (IX) Clickhouse integrating MySQL

无重复字符的最长字串

Day 3

AR虚拟增强与现实
![[C language series] - detailed explanation of file operation (Part 1)](/img/12/2d47fde0385d3f1dcb31f5efa82f7b.png)
[C language series] - detailed explanation of file operation (Part 1)

Occt learning 001 - Introduction

C language first level pointer

Clickhouse learning (VIII) materialized view

第三课threejs全景预览房间案例
随机推荐
Abstract classes and interfaces
Clickhouse learning (IX) Clickhouse integrating MySQL
弹性盒子相关知识
[C language series] - three methods to simulate the implementation of strlen library functions
Common shortcut keys for Ad
【TypeScript】深入学习TypeScript函数
牛客网编程题—【WY22 Fibonacci数列】和【替换空格】详解
Pointer
[C language series] - detailed explanation of file operation (Part 1)
Camunda 1、Camunda工作流-介绍
Differences between texture2d and texture2dproj under webgl1.0
Clickhouse learning (XI) clickhouseapi operation
Provincial and urban three-level linkage (simple and perfect)
uniapp组件之选择选项(如套餐选择)
Application of Huffman tree and Huffman coding in file compression
Wechat applet video upload component is directly uploaded to Alibaba cloud OSS
用threejs 技术做游戏跑酷
Day 3
Using POI TL to insert multiple pictures and the same data of multiple rows of cells into the table cells of word template at one time, it is a functional component for automatic merging
第三课threejs全景预览房间案例