GATE CSE C Programming Practice Test – Recursion | Set 1

Questions 61-65 of 100

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

Question 61

MCQ · Single Correct 2 mark

What is the return value of power_mod(2, 10, 1000)?

CODE
int power_mod(int b, int e, int m) {
    if (e == 0) return 1;
    long long t = power_mod(b, e / 2, m);
    t = (t * t) % m;
    if (e % 2 != 0) t = (t * b) % m;
    return t;
}
Answers for question 61

Question 62

MCQ · Single Correct 1 mark

How many call stack frames are active right before the base case returns in factorial(4)?

Answers for question 62

Question 63

MCQ · Single Correct 1 mark

What is the output of calling print_num(12)?

C
#include <stdio.h>
void print_num(int n) {
    if (n == 0) return;
    print_num(n / 2);
    printf("%d", n % 2);
}
Answers for question 63

Question 64

MCQ · Single Correct 1 mark

What is the output of the following C code?

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

Question 65

MCQ · Single Correct 2 mark

What will be the output of the following code?

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