Computer Science EngineeringHardISRO SC (CS)

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

  1. A. 111
  2. B. 103
  3. C. 133
  4. D. 102

Correct answer: A. 111

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