GATE CSE C Programming Practice Test – Recursion | Set 1

Questions 36-40 of 100

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

Question 36

MCQ · Single Correct 1 mark

What will be the output of the following C code?

C
#include <stdio.h>
int run(int n) {
    if (n <= 0) return 0;
    return n + run(n - 2);
}
int main(void) {
    printf("%d", run(7));
    return 0;
}
Answers for question 36

Question 37

MCQ · Single Correct 2 mark

How many times is the function fib() executed in total when computing fib(4)?

JAVASCRIPT
int fib(int n) {
    if (n <= 1) return n;
    return fib(n - 1) + fib(n - 2);
}
Answers for question 37

Question 38

MCQ · Single Correct 1 mark

What will be the output of the following C code?

C
#include <stdio.h>
void g(int n) {
    if (n > 0) {
        g(n - 1);
        printf("%d", n);
    }
}
int main(void) {
    g(3);
    return 0;
}
Answers for question 38

Question 39

MCQ · Single Correct 1 mark

Which recursive structure is used in quicksort partition step?

Answers for question 39

Question 40

MCQ · Single Correct 1 mark

What does the following recursive function compute?

JAVASCRIPT
int count(int arr[], int n) {
    if (n <= 0) return 0;
    return (arr[n-1] % 2 != 0) + count(arr, n-1);
}
Answers for question 40
Scroll to Top