+ 2
Hi, Why the output is 24?
2 Respuestas
+ 11
EGO hi,
First the value of $I =4 user enter value, this value will goes inside the function.
And if the value of $I is 0 or 1 then it will return 1 and for other it will recursively call the function.
So start from $I = 4 value is not 0 or 1 so goes in recursive function and return $i*f($i-1) ;
This will return for value of $I = 4,3,2
So at $I 4 it will returns
4×(4-1) which is 12
For $I = 3 it will returns
12×(3-1)=24
For $i = 2 it will returns
24×(2-1)=24
For $I = 1,0 it will returns 1 so
24×1 = 24
so final value of $I return by recursive function is 24 so output is 24
+ 2
Thank You Gaven!