Int the age (int n)
{
If (n==1)
Return (25);
The else
Return the age (n - 1) + 2;
}
Int main ()
{
int a;
A=age (5);
Printf (" % d ", a);
return 0;
}
The answer is 33, but I don't know how it is calculated, and ideas
CodePudding user response:
The age (1) : 25The age (2) : 25 + 2
The age (3) : 25 + 2 + 2
Age (4) : 25 + 2 + 2 + 2
The age (5) : 25 + 2 + 2 + 2 + 2
CodePudding user response:
"Given a bit of input, a complete single-step tracking (and press Alt + 7 key to view the Call Stack from the inside to the following out of from the inner to outer function Call history) again," is your least-hassle route to understand the working principle of the recursive function!Recursive function pay attention to the following factors
Exit criteria,
What parameters,
What, the return value is
What are local variables,
What are global variables,
When output,
, will not lead to stack overflow
CodePudding user response:
Not be accepted, thank youCodePudding user response:
Recursion is just a matter of down step by step analysisCodePudding user response:
Advice was to know about the recursive, and the recursive principle ~