Algorithms | Recursion | Question 7

What does the following function do?

filter_none

edit
close

play_arrow

link
brightness_4
code

int fun(unsigned int n)
{
    if (n == 0 || n == 1)
        return n;
  
    if (n%3 != 0)
        return 0;
  
    return fun(n/3);
}

chevron_right


(A) It returns 1 when n is a multiple of 3, otherwise returns 0
(B) It returns 1 when n is a power of 3, otherwise returns 0
(C) It returns 0 when n is a multiple of 3, otherwise returns 1
(D) It returns 0 when n is a power of 3, otherwise returns 1


Answer: (B)

Explanation:

Quiz of this Question



My Personal Notes arrow_drop_up


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.