C Expressions and Control Flow questions

Q63

GATE CS 2025 CS-1C ProgrammingNAT2 marks
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 without attempting

Answer: 46

Q19

GATE CS 2025 CS-2C ProgrammingMCQ1 mark−1/3 if wrong
Consider the following C program:
#include <stdio.h>
void stringcopy(char *, char *);
int main(){
    char a[30] = "@#Hello World!";
    stringcopy(a, a + 2);
    printf("%s\n", a);
    return 0;
}
void stringcopy(char *s, char *t) {
    while(*t)
        *s++ = *t++;
}
Which ONE of the following will be the output of the program?
Show answer without attempting

Answer: D

Q33

GATE CS 2025 CS-2C ProgrammingNAT1 mark
 int x=126,y=105;
 do {
 if(x>y) x=x-y;
 else y=y-x;
 } while(x!=y);
 printf("%d",x);
The output of the given C code segment is ________. (Answer in integer)
Show answer without attempting

Answer: 21

0/30 correct0 marks

Related topics in C Programming