GATE CSE C Programming Practice Test – Recursion | Set 1

Questions 96-100 of 100

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

Question 96

NAT · Numerical Answer 1 mark

What is the return value of mystery(16)?

CODE
int mystery(int n) {
    if (n <= 1) return 0;
    return 1 + mystery(n / 2);
}
Answers for question 96

Question 97

NAT · Numerical Answer 2 mark

What is the value printed by main()?

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

Question 98

NAT · Numerical Answer 1 mark

What is the output of the following program?

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

Question 99

NAT · Numerical Answer 1 mark

What is the return value of test(5)?

CODE
int test(int n) {
    if (n == 1) return 1;
    return test(n - 1) * n;
}
Answers for question 99

Question 100

NAT · Numerical Answer 2 mark

What is the total number of print operations executed by call p(3)?

C
#include <stdio.h>
void p(int n) {
    if (n <= 0) return;
    printf("%d", n);
    p(n - 1);
    p(n - 1);
}
Answers for question 100
Scroll to Top