776 views

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(513, 2)}$?

1. $9$
2. $8$
3. $5$
4. $2$
edited | 776 views

The function returns the sum of digits in a binary representation of the given number

so $1+0+0+0+0+0+0+0+0+1 = 2$
edited by

Final return value is 2 So option d