In the course of our learning algorithm, the Fibonacci sequence is definitely a thing to encounter, in fact, we are not in order to learn a simple sequence, more importantly, to learn his thoughts-recursion. I think recursion is the most high-frequency way to solve many algorithmic problems. The simplest description of recursion is that a function calls itself, and when it reaches a condition, it ends recursively. For example, we often use recursion in the following scenarios: Quick sort, merge sort, multiple traversal methods for binary trees, and so on. The code for the C-language implementation of the Fibonacci sequence has been uploaded to Https://github.com/chenyufeng1991/Fibonacci.
The recursive functions of the Fibonacci sequence are as follows:
。
Print each of the following:011235813...
The C language is implemented as follows:
C Language Implementation Fibonacci series
//0 1 1 2 3 5 8
#include <stdio.h>
#include <stdlib.h>
int Fibonacci (int num);
int main (int argc, const char * argv[])
{
int index = FIBONACCI (6);
printf ("%d", index);
return 0;
}
int Fibonacci (int num)
{
//recursive end condition
if (num = 0)
{return
0;
}
if (num = = 1)
{return
1;
}
Return Fibonacci (num-1) + Fibonacci (num-2);
}