Question 36
What will be the output of the following C code?
#include <stdio.h>
int run(int n) {
if (n <= 0) return 0;
return n + run(n - 2);
}
int main(void) {
printf("%d", run(7));
return 0;
}Detailed Solution
run(7) = 7 + run(5) = 7 + 5 + run(3) = 7 + 5 + 3 + run(1) = 7 + 5 + 3 + 1 + run(-1) = 16.