ProgrammingHardTCS NQT · Infosys pattern

What is printed?

What is printed?
int main(void) {
    int x = 15;
    int y = 4;
    printf("%d %d %d", x / y, x % y, (x / y) * y + (x % y));
}
  1. A. 3 4 15
  2. B. 3 3 15
  3. C. 3 3 14
  4. D. 4 3 15

Correct answer: B. 3 3 15

15/4 truncates to 3; 15%4 = 15-12=3. Verifying the division identity: (x/y)*y + (x%y) = 3*4+3 = 15 = x, as it always must for integer division/modulo.

More C Programming questions

Exams that ask this topic