#include
int g(int n) { return (n+10); }
int f(int n) { return g(n*2); }
int main() {
int sum, n;
sum=0;
for (n=1; n<3; n++)
sum += g(f(n));
printf("%d", sum);
return 0;
}
Correct Answer :
Solution :
The correct answer is 46.
To find the output of the given C program, we can trace its execution step-by-step.
First, let's analyze the functions defined in the program:
1. Function takes an integer input and returns .
2. Function takes an integer input and returns . Substituting the definition of , we have:
Inside the main function, the variable sum is initialized to 0. A for loop runs for n = 1 and n = 2 (as long as n < 3).
Iteration 1: n = 1
We calculate the value of :
Now, we compute :
Updating the sum: sum = 0 + 22 = 22.
Iteration 2: n = 2
We calculate the value of :
Now, we compute :
Updating the sum: sum = 22 + 24 = 46.
After the second iteration, the loop terminates. The final value printed is 46.
Access expert-curated educational resources and study materials—completely free.
Create, conduct, and manage professional online assessments with Mindyard. Perfect for teachers and institutes.
Copyright © 2026 Mindyard. All Rights Reserved.