Machine-translated by Google. Questions are authored in English.
Top

Discussion

Consider the following program fragment i=6720; j=4; while (i%j)==0 { i=i/j; j=j+1; } On termination j will have the value

  • A.4
  • B.8
  • C.9
  • D.6720

Answer: C

Correct answer: 9

Each pass divides i by j and then increases j:

i672016803365681
j456789

At each step the division is exact, so the loop continues - until i is 1 and j is 9, where \(1 \bmod 9 = 1\) and the loop stops. j is then 9. (Note that 6720 = 4 × 5 × 6 × 7 × 8, which is what makes every division exact.)

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.