Prashnikaप्रश्निका
Code
About
‹ Back to the paper

Question 1(iii)

1 mark

Computer ScienceISC 2022 Computer Science - Specimen paper (Semester 2), Paper 1MCQRecursion

Choose the correct option.

int Toy(int n) { return (n<=0)? 1: n%10 + Toy(n/10); } With reference to the program code given…

int Toy(int n)
{ return (n<=0)? 1: n%10 + Toy(n/10); }
With reference to the program code given above, what will the function Toy() return when the value of $n = 56$?
  • (a)65
  • (b)12
  • (c)651
  • (d)11
Open in the Recursion visualiser

Answer

Answer

Correct option: (b)

Answer: (b) 12 Toy(56) = 6 + Toy(5) = 6 + (5 + Toy(0)) = 6 + 5 + 1 = 12, since Toy(0) returns 1.