The Fibonacci sequence, the one who learned math, is 1 1 2 3 5 8 13 21 34 ...
That is, each item is the same as the first two items.
The algorithm itself is very simple, the key is to understand the idea of recursion.
Print out the Fibonacci sequence of num lengths, and paste the code directly:
====================================================================== // // copyright (C) 2014-2015 SCOTT // all rights Rese rved // // &NBSP;FILENAME:FEIBO.C // // &N Bsp created by SCOTT at 02/10/2015 // http://blog.csdn.net/ Scottly1 // //====================================================================== #include <STDIO.H&G T;int Show (int n) {if (n<=1) return n==0? 0:1;return Show (n-1) + show (n-2);} int main () {int num, i;printf ("Input Your Number:"), scanf ("%d", &num); for (I=1; I<=num; i++) {printf ("%d\n", Show (i));} return 0;}
Do not understand the best self-deduction.
Original article, reprint please famous source: http://blog.csdn.net/scottly1/article/details/43705231
"Data Structure" recursive algorithm-Fibonacci sequence