The GATE Grind

GATE 2025 CS (CS2) – Question 63

Programming and Data Structures · Programming in C · 2 marks · Numerical answer

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)

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: 46

Explanation

$f(n) = 2n + 10$ and $g(f(n)) = 2n + 20$. For n=1 this is 22 and for n=2 it is 24, so the sum is 46.