edited by
8,885 views
18 votes
18 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)}$?

  1. $345$
  2. $12$
  3. $5$
  4. $3$
edited by

3 Answers

12 votes
12 votes
A) The function returns the sum of digits of the given number.

so 5+4+3 = 12
Answer:

Related questions

18 votes
18 votes
2 answers
1
26 votes
26 votes
4 answers
2
29 votes
29 votes
6 answers
3
Kathleen asked Sep 25, 2014
13,710 views
What value would the following function return for the input $x=95$?Function fun (x:integer):integer; Begin If x 100 then fun = x – 10 Else fun = fun(fun (x+11)) End;$...