================================== Declaration ==================================
This article is original, reproduced please indicate the author and source, and ensure the integrity of the article (including this statement).
This article is not amended regularly, in order to ensure that the content is correct, suggest to read the original.
This article link: http://www.cnblogs.com/wlsandwho/p/4205524.html
======================================================================
Do not want to do things, brush a webpage, see the chaos of things on the expansion of the unconscious, this bad problem can not be changed, and wasted a lot of time to brush paste.
======================================================================
Handy to write a small code, feeling written is very simple, but for the exit condition is "1" or "2", is "<=" or "<", but it is more egg pain.
Old people do not want to be more brain, their own deduction on it, I the following code by compiling debugging determined under, no problem.
Guess which time I wrote one on the paper on the spot, I caught the shrimp.
======================================================================
To theory, please read the "Data structure and algorithm analysis C language description" and "Algorithm introduction", I put a code, do not spit groove.
======================================================================
Recursive
1#include <Windows.h>2#include <iostream>3 4 using namespacestd;5 6 long Fibonacci (long LN)7 {8 if(ln<2)9 {Ten returnLN; One } A - returnFibonacci (ln-1) +fibonacci (ln-2); - } the - intMain () - { -LONG Ls=fibonacci ( +); + - return 0; +}
Tail recursion
1#include <Windows.h>2#include <iostream>3 4 using namespacestd;5 6Long Fibonacci (Long Ln,long la=1, LONG lb=1)7 {8 if(ln==2|| ln==1)9 {Ten returnLB; One } A - returnFibonacci (ln-1, lb,la+LB); - } the - intMain () - { -LONG Ls=fibonacci ( +); + - return 0; +}
Recursive
1#include <Windows.h>2#include <iostream>3 4 using namespacestd;5 6 long Fibonacci (long LN)7 {8LONG ls=1;9LONG la=1;TenLONG lb=1; One A for(LONG lcount=3; lcount<=ln;lcount++) - { -ls=la+LB; theLa=LB; -lb=LS; - } - + returnLS; - } + A intMain () at { -LONG Ls=fibonacci ( +); - - return 0; -}
Recursive recursive tail recursive C + + implementation of Fibonacci sequence