Recursion Quiz doubt in question 1

How the ans to first question is 1 if we take n=6
ans is 0 .So i think ans is second option

Q1. Recursion output 1
What does the following function do?

int fun(unsigned int n)
{
if (n == 0 || n == 1)
return n;

if (n%3 != 0)
    return 0;

return fun(n/3);

}

options are

It returns 1 when n is a multiple of 3, otherwise returns 0.

It returns 1 when n is a power of 3, otherwise returns 0.

It returns 0 when n is a multiple of 3, otherwise returns 1.

It returns 0 when n is a power of 3, otherwise returns 1.

@Rememberthename
hello sumit,
please share question as well

@Rememberthename
yeah,i also think answer should be b.

1 Like

2nd Option is correct, i.e.,

It returns 1 when n is a power of 3, otherwise returns 0

because if we will pass any number other than the power of three, so due to recursion at the end it willl return 0 only. For example,
intputoutput
3 – 1
9 – 1
6 – 0
12 – 0