Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Consider the following recursive C function t... Start Learning for Free
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;
}
Q.
What is the return value of the function foo when it is called as foo(345, 10) ?
  • a)
    345
  • b)
    12
  • c)
    5
  • d)
    3
Correct answer is option 'B'. Can you explain this answer?
Verified Answer
Consider the following recursive C function that takes two argumentsun...
The call foo(345, 10) returns sum of decimal digits (because r is 10) in the number n. Sum of digits for 345 is 3 + 4 + 5 = 12.
View all questions of this test
Most Upvoted Answer
Consider the following recursive C function that takes two argumentsun...
The function foo takes two unsigned integer arguments n and r. It calculates the sum of the first r terms of the sequence {n, n+1, n+2, ...} using recursion.

The base case is when r equals 0, in which case the function returns 0. Otherwise, it recursively calls itself with n+1 and r-1, and adds the result to n.

For example, if we call foo(3, 4), it will calculate the sum of the first 4 terms of the sequence {3, 4, 5, 6}, which is 3+4+5+6=18.
Explore Courses for Computer Science Engineering (CSE) exam

Similar Computer Science Engineering (CSE) Doubts

Top Courses for Computer Science Engineering (CSE)

Consider the following recursive C function that takes two argumentsunsigned int foo(unsigned int n, unsigned int r){if(n >0) return (n%r + foo (n/r, r));else return 0;}Q.What is the return value of the function foo when it is called as foo(345, 10) ?a)345b)12c)5d)3Correct answer is option 'B'. Can you explain this answer?
Question Description
Consider the following recursive C function that takes two argumentsunsigned int foo(unsigned int n, unsigned int r){if(n >0) return (n%r + foo (n/r, r));else return 0;}Q.What is the return value of the function foo when it is called as foo(345, 10) ?a)345b)12c)5d)3Correct answer is option 'B'. Can you explain this answer? for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Consider the following recursive C function that takes two argumentsunsigned int foo(unsigned int n, unsigned int r){if(n >0) return (n%r + foo (n/r, r));else return 0;}Q.What is the return value of the function foo when it is called as foo(345, 10) ?a)345b)12c)5d)3Correct answer is option 'B'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Consider the following recursive C function that takes two argumentsunsigned int foo(unsigned int n, unsigned int r){if(n >0) return (n%r + foo (n/r, r));else return 0;}Q.What is the return value of the function foo when it is called as foo(345, 10) ?a)345b)12c)5d)3Correct answer is option 'B'. Can you explain this answer?.
Solutions for Consider the following recursive C function that takes two argumentsunsigned int foo(unsigned int n, unsigned int r){if(n >0) return (n%r + foo (n/r, r));else return 0;}Q.What is the return value of the function foo when it is called as foo(345, 10) ?a)345b)12c)5d)3Correct answer is option 'B'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of Consider the following recursive C function that takes two argumentsunsigned int foo(unsigned int n, unsigned int r){if(n >0) return (n%r + foo (n/r, r));else return 0;}Q.What is the return value of the function foo when it is called as foo(345, 10) ?a)345b)12c)5d)3Correct answer is option 'B'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider the following recursive C function that takes two argumentsunsigned int foo(unsigned int n, unsigned int r){if(n >0) return (n%r + foo (n/r, r));else return 0;}Q.What is the return value of the function foo when it is called as foo(345, 10) ?a)345b)12c)5d)3Correct answer is option 'B'. Can you explain this answer?, a detailed solution for Consider the following recursive C function that takes two argumentsunsigned int foo(unsigned int n, unsigned int r){if(n >0) return (n%r + foo (n/r, r));else return 0;}Q.What is the return value of the function foo when it is called as foo(345, 10) ?a)345b)12c)5d)3Correct answer is option 'B'. Can you explain this answer? has been provided alongside types of Consider the following recursive C function that takes two argumentsunsigned int foo(unsigned int n, unsigned int r){if(n >0) return (n%r + foo (n/r, r));else return 0;}Q.What is the return value of the function foo when it is called as foo(345, 10) ?a)345b)12c)5d)3Correct answer is option 'B'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider the following recursive C function that takes two argumentsunsigned int foo(unsigned int n, unsigned int r){if(n >0) return (n%r + foo (n/r, r));else return 0;}Q.What is the return value of the function foo when it is called as foo(345, 10) ?a)345b)12c)5d)3Correct answer is option 'B'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev