Free Practice / PYQ

GATE CSE C Programming Practice Test – Recursion | Set 1

Questions 1-5 of 100

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

Question 1

MCQ · Single Correct 1 mark

What is the output of the following C function when called with fun(5)?

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

💡 Right-click an option to strike it out

Question 2

MCQ · Single Correct 1 mark

Consider the following recursive C function:

C
void solve(int n) {
    if (n <= 0) return;
    printf("%d ", n % 2);
    solve(n / 2);
}

What is printed when solve(13) is called?

Answers for question 2

💡 Right-click an option to strike it out

Question 3

MCQ · Single Correct 1 mark

What does the following recursive C function compute for a non-negative integer n?

JAVASCRIPT
int foo(int n) {
    if (n == 0) return 0;
    return (n % 10) + foo(n / 10);
}
Answers for question 3

💡 Right-click an option to strike it out

Question 4

MCQ · Single Correct 2 mark

Consider the following recursive C function:

CODE
int my_func(int a, int b) {
    if (b == 0) return 0;
    if (b % 2 == 0) return my_func(a + a, b / 2);
    return my_func(a + a, b / 2) + a;
}

What does my_func(a, b) calculate for positive integers a and b?

Answers for question 4

💡 Right-click an option to strike it out

Question 5

MCQ · Single Correct 1 mark

What is the output of the following C program?

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

💡 Right-click an option to strike it out

Scroll to Top