GATE Assistant

Past questions › Computer Science and Information Technology › GATE 2025 set1

GATE 2025 set1 · CS · NAT · 2 marks · Programming and Data Structures › C Programming Fundamentals

GATE 2025 set1 Computer Science and Information Technology question: Consider the following C program: code The value printed by the given C program is .…

Consider the following C program:

#include <stdio.h>
int gate (int n) {
    int d, t, newnum, turn;
    newnum = turn = 0; t=1;
    while (n>=t) t *= 10;
    t /=10;
    while (t>0) {
        d = n/t;
        n = n%t;
        t /= 10;
        if (turn) newnum = 10*newnum + d;
        turn = (turn + 1) % 2;
    }
    return newnum;
}
int main () {
    printf ("%d", gate(14362));
    return 0;
}

The value printed by the given C program is _______ . (Answer in integer)

Show answer

Official answer: 46

Practise this question with exam-style marking

Discussion

No discussion yet.

Join the discussion