GATE CSE C Programming Practice Test – Recursion | Set 1

Questions 11-15 of 100

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

Question 11

MCQ · Single Correct 1 mark

What does the following recursive function return when called as count_bits(13)?

JAVASCRIPT
int count_bits(int n) {
    if (n == 0) return 0;
    return (n & 1) + count_bits(n >> 1);
}
Answers for question 11

Question 12

MCQ · Single Correct 1 mark

What is printed by the call show(123) for the following function?

C
void show(int n) {
    if (n == 0) return;
    show(n / 10);
    printf("%d", n % 10);
}
Answers for question 12

Question 13

MCQ · Single Correct 1 mark

What is the return value of gcd(48, 18) using Euclid's recursive algorithm?

CODE
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
Answers for question 13

Question 14

MCQ · Single Correct 1 mark

What happens if a recursive function does not have a base case?

Answers for question 14

Question 15

MCQ · Single Correct 1 mark

What is the output of the following C code?

C
#include <stdio.h>
int fun(int n) {
    if (n == 1) return 0;
    return 1 + fun(n / 2);
}
int main(void) {
    printf("%d", fun(16));
    return 0;
}
Answers for question 15
Scroll to Top