#include<stdio.h>
int counter=0;
int calc (int a, int b) {
int c;
counter++;
if(b==3) return (a*a*a);
else {
c = calc(a, b/3);
return (c*c*c);
}
}
int main() {
calc(4, 81);
printf("%d", counter);
}
Here counter is a global variable, you can use anywhere of the program,
Now when main() call the calc() by the value (4,81)
--> counter=counter+1 so now counter=1.
Now for 81 not eq to 3 so else block got executed and Now b=81/3=27.
Again counter increased by 1 and now counter =2.
In this way when b=3 counter will become 4 and cacl() return 64;
counter=3
int calc(4,3)
{
int c;
counter++;
if(b==3) return (a*a*a);
else {
c = calc(a, b/3);
return (c*c*c);
}
}
So, ans is 4.