Consider the function in C code :
Cal(a, b)
{
if (b != 1)
{
if (a != 1)
{
printf("*");
Cal(a/2, b);
}
}
else
{
b = b - 1;
Cal(10, b);
}
}
How many times * is going to be printed, if the function is called with
Cal(10, 10) ?
Observe recursion:
Each call prints * while dividing a by 2.
Sequence:
10 → 5 → 2 → 1
For each b value, stars printed = 3.
b decreases from 10 to 1.
Thus:
$9 \times 3 = 27$
Total stars printed = 27.
Online Test Series, Information About Examination,
Syllabus, Notification
and More.
Online Test Series, Information About Examination,
Syllabus, Notification
and More.