Computer Science EngineeringHardISRO SC (CS)

Consider the following C fragment. int c=0; for(int i=0;i<20;i++) for(int j=i+1;j<20;j++) for(int k=j+1;k<20;k++) c++; What is c at the end?

  1. A. 3420
  2. B. 190
  3. C. 1540
  4. D. 1140

Correct answer: D. 1140

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