200 views

1 Answer

1 1 vote

The function call is $\texttt{calc(4)}$.

Now expand it step by step.

$\texttt{calc(4) = 4 + calc(3)}$

$\texttt{calc(3) = 3 + calc(2)}$

$\texttt{calc(2) = 2 + calc(1)}$

The base condition is $\texttt{calc(1) = 2}$.

So,

$\texttt{calc(2) = 2 + 2 = 4}$

$\texttt{calc(3) = 3 + 4 = 7}$

$\texttt{calc(4) = 4 + 7 = 11}$

Therefore, the output is $\texttt{11}$.

Answer:
Position:
Show:

Related questions

8 8 votes
1 1 answer
229
229 views
GO Classes asked Jun 6
229 views
What is the output of the following code?#include <stdio.h void change(int *p, int *q) { *p = *p + 4; *q = *p + *q; p = q; *p = *p - 3; } int main() { int a = 6, b = 10; ...
9 9 votes
1 1 answer
215
215 views
GO Classes asked Jun 6
215 views
What is the output of the following code?#include <stdio.h int main() { int i, j, count = 0; for (i = 1; i <= 4; i++) { for (j = 1; j <= 4; j++) { if (i * j 6) break; co...
8 8 votes
1 1 answer
227
227 views
GO Classes asked Jun 6
227 views
What is the output of the following code?#include <stdio.h void fun() { static int x = 3; int y = 2; x = x + y; y = y + x; printf("%d ", x); } int main() { fun(); fun(); ...
8 8 votes
1 1 answer
237
237 views
GO Classes asked Jun 6
237 views
What is the output of the following code?#include <stdio.h int main() { int a = 8, b = 12; int *p = &a; int *q = &b; *p = *p + *q; q = p; *q = *q - 5; printf("%d %d", a, ...