Computer Science EngineeringVery hardISRO SC (CS)

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

  1. A. 63
  2. B. 57
  3. C. 240
  4. D. 126

Correct answer: A. 63

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