• edited by
11,922 views
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)}$?

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

3 Answers

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

so 5+4+3 = 12
Answer:
Position:
Show:

Related questions

28 28 votes
2 answers 2 answers
9.3k
9.3k views
go_editor asked Apr 21, 2016
9,286 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...
75 75 votes
4 answers 4 answers
24.7k
24.7k views
go_editor asked Sep 29, 2014
24,682 views
On a non-pipelined sequential processor, a program segment, which is the part of the interrupt service routine, is given to transfer $500$ bytes from an I/O device to mem...
43 43 votes
5 answers 5 answers
17.4k
17.4k views
go_editor asked Sep 30, 2014
17,351 views
What is the value printed by the following C program?#include<stdio.h int f(int *a, int n) { if (n <= 0) return 0; else if (*a % 2 == 0) return *a+f(a+1, n-1); else retur...
36 36 votes
6 answers 6 answers
20.1k
20.1k views
Kathleen asked Sep 25, 2014
20,148 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;$89...