GATE CSE C Programming Practice Test – Recursion | Set 1

Questions 56-60 of 100

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

Question 56

MCQ · Single Correct 2 mark

What is the output of calling compute(4)?

C
#include <stdio.h>
int compute(int n) {
    if (n <= 1) return 1;
    return n * compute(n - 2);
}
int main(void) {
    printf("%d", compute(4));
    return 0;
}
Answers for question 56

Question 57

MCQ · Single Correct 1 mark

What does the following function return for is_palindrome("radar", 0, 4)?

JAVASCRIPT
int is_palindrome(char *s, int l, int r) {
    if (l >= r) return 1;
    if (s[l] != s[r]) return 0;
    return is_palindrome(s, l + 1, r - 1);
}
Answers for question 57

Question 58

MCQ · Single Correct 1 mark

What will be the output of the following C code?

C
#include <stdio.h>
int f(int n) {
    if (n <= 0) return 0;
    return (n % 10 == 0) + f(n / 10);
}
int main(void) {
    printf("%d", f(102030));
    return 0;
}
Answers for question 58

Question 59

MCQ · Single Correct 1 mark

Which sorting algorithm heavily relies on recursive divide and conquer?

Answers for question 59

Question 60

MCQ · Single Correct 2 mark

What is the output of the C function below for func(3)?

C
#include <stdio.h>
void func(int n) {
    static int d = 1;
    printf("%d %d ", n, d);
    d++;
    if (n > 1) func(n - 1);
    printf("%d %d ", n, d);
}
Answers for question 60
Scroll to Top