Question 91
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;
}Detailed Solution
calc(8) = 8 + 6 + 4 + 2 + calc(0) = 8 + 6 + 4 + 2 + 1 = 21.
✓ Saved