C Programming · Question 22 · Medium
What will be the output of the following C program?
#include <stdio.h>
int f(int n) {
return n <= 1 ? 1 : n * f(n - 2);
}
int main(void) {
printf("%d", f(7));
return 0;
}
- 5040
- 35
- 105
- 945
Answer and explanation
Answer: C. 105
Explanation: f(7) = 7 × f(5) = 7 × 5 × f(3) = 7 × 5 × 3 × f(1) = 105, the product of the odd numbers up to 7.
Previous: What will be the output of the following C program? · Next: What will be the output of the following C program?
Practise c programming
Try a fresh set of c programming questions with an explanation after every answer, free and without signing up: C Programming practice. Or sit a full placement mock test.
More c programming questions
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
- What will be the output of the following C program?
More technical & programming practice
Java · Python · Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge