Aspire's Library

A Place for Latest Exam wise Questions, Videos, Previous Year Papers,
Study Stuff for MCA Examinations - NIMCET

Previous Year Question (PYQs)



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) ?






Solution

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.

Click Here to
View More


Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More

Ask Your Question or Put Your Review.

loading...