Speaking of recursion, it's easy to think of n!. , the Fibonacci sequence (the number of rabbits), of course, is a very good understanding of the problem. Personally, it is the Hanoi and string inverse output that best reflects the recursion essence. Hanoi tower problem only need to think one step, other problems to the computer, it is very good to prove that recursion is lazy people dedicated algorithm. This alone is sufficient to conceal the drawback of inefficient recursion. As we all know, recursion is the process by which a function calls itself. In the C language, the function calls itself and calls other functions without a bit of distinction. is to save the scene, function calls, restore the site process, which is popular, in our professional terminology, the essence of recursion is into the stack and the process of the stack. Explained here, recursive implementation of string output problem is very good solution. Directly on the code, understand the problem, grasp the whole into the stack of the nature of the stack is good.
Code
4* Filename: A. C5*6*Description:7*8* Version:1.0 9*created:2014 December 29 09:02 57 secondsTen*Revision:none One*COMPILER:GCC A* -*author:3me (), -*Organization: the* -* ===================================================================================== -*/ -#include <stdlib.h> +#include <stdio.h> - /** = = FUNCTION ====================================================================== * NAME:PRI NT $ * description:24 * ===================================================================================== 25 /c5>*/ - void -print () - { in intC; - if((c = GetChar ())! =-1 ) toprint (); + Else -printf"\ n"); the if(c! =-1 ) *printf"%c", c); $ return; Panax Notoginseng}/*-----End of function Print-----*/ - /** = = = FUNCTION ====================================================================== * Name:mai n * description:42 * ===================================================================================== 43
*/ - int $Main (intargcChar*argv[]) $ { -print (); - the returnexit_success; -}/*----------End of function main----------*/ Wuyi
Reverse string output--recursion