Question
Consider the following C program:
#include <stdio.h>
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;
}
The output of the given C program is ________. (Answer in integer)
Official answer and solution
- Official answer
- 46
- From
- Official GATE 2025 answer key
Solution
Express g(f(n)) algebraically as and sum over .
From the function definitions:
The for loop executes for and :
- For :
- For :
Thus sum .
Final answer
46
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2025 Computer Science and Information Technology - Session 2 (CS2)
- Question
- 63 of 65
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.