I am facing problems in understanding how calling function works,how to call a function in another function and recurrsions can you please help me out
The best way to get is to do all the steps on a paper. For example, let’s take the factorial function:
int factorial( int a ) /* function */
{
if( a == 0 || a == 1)
{
return 1;
}
else
{
return a*factorial(a-1);
}
}
Let’s call factorial(2).
On a paper, you can write all the steps i.e., firstly, a is not 0 or 1 so, 2*(factorial(1)) will be returned. Just hold up here and again do the same for factorial(1), this will return 1 and finally, you will replace 2*(factorial(1)) with 2*1.
New Questions |
---|
trustworthy online casino in New Zealand - C
|
SSM Exam - Other
|
SPC Exam - Other
|
SAFe-Practitioner Exam - Other
|
SAFe-Agilist Exam - Other
|
P_SAPEA_2023 Exam - Other
|
POPM Exam - Other
|