Home > Back-end >  Ask a question
Ask a question

Time:03-25

# include & lt; stdio.h>
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) : 25
The 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 you

CodePudding user response:

Recursion is just a matter of down step by step analysis

CodePudding user response:

Advice was to know about the recursive, and the recursive principle ~
  • Related