GATE | GATE CS 2011 | Question 48
Consider the following recursive C 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; } |
chevron_right
filter_none
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)
Explanation: The call foo(345, 10) returns sum of decimal digits (because r is 10) in the number n. Sum of digits for 345 is 3 + 4 + 5 = 12.
This solution is contributed by Pranjul Ahuja
Quiz of this Question
Recommended Posts:
- GATE | GATE CS 2011 | Question 4
- GATE | GATE CS 2011 | Question 65
- GATE | GATE CS 2011 | Question 6
- GATE | GATE CS 2011 | Question 8
- GATE | GATE CS 2011 | Question 9
- GATE | GATE CS 2011 | Question 10
- GATE | GATE CS 2011 | Question 11
- GATE | GATE CS 2011 | Question 65
- GATE | GATE CS 2011 | Question 13
- GATE | GATE CS 2011 | Question 14
- GATE | GATE CS 2011 | Question 65
- GATE | GATE CS 2011 | Question 40
- GATE | GATE CS 2011 | Question 15
- GATE | GATE CS 2011 | Question 3
- GATE | GATE CS 2011 | Question 2




