Programming for Problem Solving (3110003) MCQs

MCQs of Recursion

Showing 11 to 10 out of 20 Questions
11.
The data structure used to implement recursive function calls _____
(a) Array
(b) Linked List
(c) Queue
(d) Stack
Answer:

Option (d)

12.
What is the output?

main()
{
    int n,i;
    n=f(6);
    printf("%d",n);
}
f(int x)
{
    if(x==2)
            return 2;
    else
    {
        printf("+");
        f(x-1);
    }
}

(a) ++++2
(b) +++++2
(c) +++++
(d) 2
Answer:

Option (a)

13.
What is the output?

main()
{
    int n=10;
    int f(int n);
    printf("%d",f(n));
}
int f(int n)
{
    if(n>0)
        return(n+f(n-2));
}

(a) 10
(b) 80
(c) 30
(d) Infinite loop
Answer:

Option (c)

14.
What is the output?
int main()
{
printf("Hello");
main();
return 0;
}
(a) Hello is printed once
(b) Hello infinite number of times
(c) Hello is not printed at all
(d) 0 is returned
Answer:

Option (b)

15.
Which of the following is true?
(a) Recursion is always better than iteration
(b) Recursion uses more memory compared to iteration
(c) Recursion uses less memory compared to iteration
(d) Iteration is always better and simpler than recursion
Answer:

Option (b)

16.
What is the output of func(4);?

int func(int number) 

    if(number <= 0) 
        return 1;                             
    else 
        return number * func(number-1);   
}

(a) 12
(b) 24
(c) 1
(d) 0
Answer:

Option (b)

17.
What is the output of func(3,8)?

int func(int a, int b)
{
    if(b==0)
        return 0;
    if(b==1)
        return a;
 
    return a + func(a,b-1); 
}

(a) 11
(b) 24
(c) 22
(d) 21
Answer:

Option (b)

18.
What is the output of print(12)?

void print(int n)
{
    if (n == 0)
        return;
    printf("%d", n%2);
    print(n/2);
}

(a) 0011
(b) 1100
(c) 1001
(d) 1000
Answer:

Option (a)

19.
What is the output of sum(8)?

int sum(int n)
{
    if (n==0)
       return n;
    else
       return n + sum(n-1);    
}

(a) 40
(b) 8
(c) 36
(d) 15
Answer:

Option (c)

20.
What is the output?

int rec(int num)
{
    return (num) ? num%10 + rec(num/10):0;
}
void main()
{
    printf("%d",rec(4567));
}

(a) 4
(b) 12
(c) 22
(d) 21
Answer:

Option (c)

Showing 11 to 10 out of 20 Questions