wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

Consider the following recursive C function that take 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 foo when it is called as foo(345, 10)?

A
12
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
B
5
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
345
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
3
No worries! We‘ve got your back. Try BYJU‘S free classes today!
Open in App
Solution

The correct option is A 12
Consider the following recursive C function Ex
(n, r)
{
if (n > 0) return (n%r) + foo (n/r, r);
else return 0;
}
Value return by the function foo (345, 10);
foo(345, 10)

5 + foo (34, 10)

4 + foo (3, 10)

3 + foo (0,10)

0
The return values is 5 + 4+ 3 = 12

flag
Suggest Corrections
thumbs-up
1
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Formula for Sum of N Terms of an AP
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon