GATE Computer ScienceHardGATE CS (PYQ pattern)

int s = 0; for (int i = 0; i < 6; i++) { if (i == 1) continue; switch (i % 4) { case 0: s += 1; case 1: s += 10; break; case 2: s += 100; default: s += 1000; } if (i == 4) break; } printf("%d", s); What is printed?

  1. A. 1122
  2. B. 2132
  3. C. 2122
  4. D. 2012

Correct answer: C. 2122

i = 0: 11; i = 1 skipped; i = 2: 1100; i = 3: 1000; i = 4: 11 and then break. Sum = 2122.

More Programming and Data Structures (GATE) questions

Exams that ask this topic