GATE 2013 Comprehensive Information Page @ http://www.codeblocks.info/2012/08/gate-2013.html
Consider the following recursive function that takes two arguments
unsigned int foo(unsigned int n, unsigned int r) {
if(n > 0) return ((n % r) + foo(n / r, r));
else return 0;
}
What is the return value of the function "foo" when it is called as foo(345, 10)?
(A) 345
(B) 12
(C) 5
(D) 3
Answer: (B) 12
5 + 4 + 3 + 0 = 12
What is the return value of the function "foo" when it is called as foo(513, 2)?
(A) 9
(B) 8
(C) 5
(D) 2
Answer: (D) 2
Written by Munia Balayil
No comments:
Post a Comment