hamburger menu
All Coursesall course arrow
adda247
reward-icon
adda247
    arrow
    arrow
    arrow
    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
    Question



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

    A.

    25

    B.

    23

    C.

    24

    D.

    27

    Correct option is D

    This recursive function repeatedly prints an asterisk (*) based on the values of a and b. The function divides a by 2 each time, and when a reaches 1, it reduces b by 1 and resets a to 10. This creates a recursive loop that prints * each time it recurses until b equals 1.
    Information Booster:
    · Each call reduces a by half until a equals 1.
    · When a becomes 1, b is decremented by 1, and a is reset to 10, leading to more recursive calls.
    · This pattern continues until b reaches 1, resulting in 27 asterisk prints.

    Free Tests

    Free
    Must Attempt

    Basics of Education: Pedagogy, Andragogy, and Hutagogy

    languageIcon English
    • pdpQsnIcon10 Questions
    • pdpsheetsIcon20 Marks
    • timerIcon12 Mins
    languageIcon English
    Free
    Must Attempt

    UGC NET Paper 1 Mock Test 1

    languageIcon English
    • pdpQsnIcon50 Questions
    • pdpsheetsIcon100 Marks
    • timerIcon60 Mins
    languageIcon English
    Free
    Must Attempt

    Basics of Education: Pedagogy, Andragogy, and Hutagogy

    languageIcon English
    • pdpQsnIcon10 Questions
    • pdpsheetsIcon20 Marks
    • timerIcon12 Mins
    languageIcon English

    Similar Questions

    test-prime-package

    Access ‘UGC NET Computer Science’ Mock Tests with

    • 60000+ Mocks and Previous Year Papers
    • Unlimited Re-Attempts
    • Personalised Report Card
    • 500% Refund on Final Selection
    • Largest Community
    students-icon
    368k+ students have already unlocked exclusive benefits with Test Prime!
    Our Plans
    Monthsup-arrow