ISRO | ISRO CS 2020 | Question 34
Consider the following recursive C function that takes two arguments
unsigned int rer (unsigned int n, unsigned int r) { if (n > 0) return (n% r + rer(n/r, r)); else return 0; }
What is the return value of the function rer when it is called as rer (513, 2) ?
(A) 9
(B) 8
(C) 5
(D) 2
Answer: (D)
Explanation:
= rer (513, 2) = 513% 2 + 256% 2 + 128% 2 + 64% 2 + 32% 2 + 16% 2 + 8%2 + 4%2 + 2%2 + 1%2
Hence, output will be,
= 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 = 2
So, option (D) is correct.
Quiz of this Question
Please Login to comment...