GATE CSE C Programming Practice Test – Recursion | Set 1

Questions 16-20 of 100

Your score 0/100 0 answered
Correct 0 Incorrect 0 Unanswered 100 Accuracy 0%

Question 16

MCQ · Single Correct 2 mark
CODE
Consider the function:
int f(int n) {
    if (n <= 0) return 1;
    return f(n - 1) + f(n - 1);
}
What is the time complexity of f(n)?
Answers for question 16

Question 17

MCQ · Single Correct 2 mark

What is the output of calling main_func(5) for the following code?

C
#include <stdio.h>
void main_func(int n) {
    if (n > 0) {
        main_func(--n);
        printf("%d ", n);
        main_func(--n);
    }
}
Answers for question 17

Question 18

MCQ · Single Correct 1 mark

What will be the output of the following recursive function for f(3, 4)?

JAVASCRIPT
int f(int x, int y) {
    if (y == 0) return 1;
    return x * f(x, y - 1);
}
Answers for question 18

Question 19

MCQ · Single Correct 1 mark

What is the return value of mystery(5) for the following function?

CODE
int mystery(int n) {
    if (n == 1) return 1;
    return n * n + mystery(n - 1);
}
Answers for question 19

Question 20

MCQ · Single Correct 1 mark

In C, where are the parameters and local variables of a recursive function call stored?

Answers for question 20
Scroll to Top