Computer Science EngineeringVery hardISRO SC (CS)

Consider the following C fragment. int c=0; for(int i=200;i>=1;i/=2) for(int j=0;j<i;j++) c++; What is c at the end? (integer division)

  1. A. 397
  2. B. 396
  3. C. 400
  4. D. 1600

Correct answer: A. 397

Simulating the loops gives 397. The distractors come from the usual slips: off-by-one at a boundary (< vs <=), dropping a loop level, or using a cruder asymptotic estimate instead of the exact count.

More Algorithms, Data Structures & Programming (ISRO CS) questions

Exams that ask this topic