GATE CSE C Programming Practice Test – Recursion | Set 1

Questions 91-95 of 100

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

Question 91

NAT · Numerical Answer 1 mark

What is the output of the following C program?

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

Question 92

NAT · Numerical Answer 1 mark

What value is returned by the call f(12, 18)?

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

Question 93

NAT · Numerical Answer 2 mark

How many asterisk (*) characters are printed by call stars(4)?

C
#include <stdio.h>
void stars(int n) {
    if (n <= 0) return;
    printf("*");
    stars(n - 1);
    stars(n - 1);
}
Answers for question 93

Question 94

NAT · Numerical Answer 1 mark

What is the output of the following C code?

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

Question 95

NAT · Numerical Answer 1 mark

What is the value of foo(3, 4)?

CODE
int foo(int a, int b) {
    if (b == 0) return 0;
    return a + foo(a, b - 1);
}
Answers for question 95
Scroll to Top