Question discussion

What is the output of the following C program?#include int f(int n) { if (n

1513Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C program?

#include <stdio.h>
int f(int n) {
    if (n <= 1) return 1;
    return n * f(n - 2);
}
int main() {
    printf("%d", f(7));
    return 0;
}
  • A105
  • B35
  • C21
  • D5040
Correct answer: A

Explanation

f(7) = 7 × f(5) = 7 × 5 × f(3) = 7 × 5 × 3 × f(1) = 105.

Discussion 0

Nobody has replied yet. Start the discussion!