23 23 votes 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; } What is the return value of the function $\text{foo}$ when it is called as $\text{foo(345, 10)}$? $345$ $12$ $5$ $3$ Algorithms gatecse-2011 algorithms recursion identify-function normal + – go_editor 11.9k views answer comment Share Follow Print See all 4 Comments 4 4 Comments reply Manu Thakur commented Dec 25, 2017 reply Follow flag Sum of the digits in the given decimal number 345, 3+4+5 = 12 is the correct option. 1 1 replyShare abhijit_m commented Jan 30, 2020 reply Follow flag would the answer have been any different for signed int ? 0 0 replyShare Kiyoshi commented Jun 7, 2021 reply Follow flag No, it will remain same. 0 0 replyShare Amjad. commented Apr 15, 2025 reply Follow flag check this comment : https://gateoverflow.in/43324/gate-cse-2011-question-49?show=236150#c236150 0 0 replyShare Please log in or register to add a comment.
Best answer 31 31 votes Red colour represents return values. Answer is 12. Rajesh Pradhan answered Nov 11, 2016 • edited Jul 6, 2019 by Sukanya Das Rajesh Pradhan comment Share Follow See 1 comment 1 1 comment reply pavansan commented Jan 4, 2025 reply Follow flag got it 0 0 replyShare Please log in or register to add a comment.
13 13 votes A) The function returns the sum of digits of the given number. so 5+4+3 = 12 Danish answered Jan 17, 2015 Danish comment Share Follow 0 reply Please log in or register to add a comment.
3 3 votes Following recursive calls Pronomita Dey 1 answered Jan 23, 2018 Pronomita Dey 1 comment Share Follow 0 reply Please log in or register to add a comment.