recursion (recursion)
The C-language function can make a recursive call (recursive called), which means that the function itself can be called within the function. When a function makes a recursive call, the variables it uses are stacked in the stacking area, and each time a return is executed, the variables used by the function in that layer call are returned from the stack. properties of L-l recursive function
1. (1) Each execution of a return statement, the scope of the problem narrowed
2. (2) having a condition for terminating the recursion
Program Examples : Recursive
int factorial(int j) { if (n==1) return (1); Else Return (nfactorial(n-1)); } void Main (void) { int i; for (i=0; i< 5; i++) printf ("%d! =%d/n ", I, factorial(i)); }
|
Result: 1! is 1 2! is 2 3! is 6 4! is 24
|
internal processing of L-l recursive function
1.1. Call of the general function
2.2. Call of recursive function
01 |
|
02 |
|
03 |
|
04 |
|
05 |
int list[6] = {1, 2, 3, 4, 5, 6}; /* Array Contents */ |
06 |
|
07 |
/* ----------------------------------------------------------------------------------- */ |
08 |
/* Recursive array inverse printing function */ |
09 |
/* ----------------------------------------------------------------------------------- */ |
10 |
void Invert_array (int j) |
11 |
{ |
12 |
if (J < 6) &n |