Consider the following C code :
#include<stdio.h>
int temp = 0;
int fun(int x, int y)
{
int z;
temp++;
if (y == 3)
return (x*x*x);
else
{
z = fun(x, y/3);
return (z*z*z);
}
}
int main()
{
fun(4,81);
printf("%d", temp);
}
What will be the output of the above code ?
Recursive calls divide $y$ by $3$ each time.
Call sequence:
$fun(4,81)$
$fun(4,27)$
$fun(4,9)$
$fun(4,3)$
Total calls = 4
Each call increments temp.
So
$temp = 4$
Online Test Series, Information About Examination,
Syllabus, Notification
and More.
Online Test Series, Information About Examination,
Syllabus, Notification
and More.