Computer Science EngineeringHardISRO SC (CS)

Consider the following C fragment. int c=0; int x=100; while(x>0){ for(int j=0;j<x;j++) c++; x/=3; } What is c at the end? (integer division)

  1. A. 148
  2. B. 147
  3. C. 197
  4. D. 150

Correct answer: A. 148

Simulating the loops gives 148. 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