GATE Computer ScienceHardGATE CSE · ISRO

int c = 0; for (int i = 1; i < 100; i *= 2) for (int j = 0; j < i; j++) c++; What is the final value of c?

  1. A. 126
  2. B. 128
  3. C. 100
  4. D. 127

Correct answer: D. 127

i takes 1, 2, 4, 8, 16, 32, 64, and the inner loop runs i times: sum = 127.

More Programming and Data Structures (GATE) questions

Exams that ask this topic