Question 56
What is the output of calling compute(4)?
C
#include <stdio.h>
int compute(int n) {
if (n <= 1) return 1;
return n * compute(n - 2);
}
int main(void) {
printf("%d", compute(4));
return 0;
}Detailed Solution
compute(4) = 4 * compute(2) = 4 * 2 * compute(0) = 4 * 2 * 1 = 8 (calculates double factorial 4!!).
✓ Saved