Recursive algorithm for 10!

Recursive algorithm is calling himself, calling the cycle. Algorithm is used to solve the problem. Relatively simple and easy to analyze.
Recursive There are two basic elements: the boundary conditions that determine when to stop running recursive, also called recursive exports, the other is the recursive mode, that is, how to break down big problems into small problems, also known as recursive body.
GETR int (int NUM) {
IF (NUM ==. 1)
return NUM;
return GETR (. 1-NUM) NUM;
}
example: recursive factorial 10! .
static int GETR public (int NUM) {
IF (NUM ==. 1). 1 == // recursive condition NUM
return NUM;
return GETR (. 1-NUM)
NUM; // GETR (. 1-NUM) * NUM recursion body
}

In the main method call:
GETR (10);

Guess you like

Origin www.cnblogs.com/jasonboren/p/11568913.html