Consider the following program segment in C programming language: i = 6720; j…

2018

Consider the following program segment in C programming language:

i = 6720; j = 4;

while ((i % j) == 0)

{i = i / j; j = j + 1;}

On termination, j will have the value:

  1. A.

    4

  2. B.

    8

  3. C.

    9

  4. D.

    6720

Attempted by 177 students.

Show answer & explanation

Correct answer: C

The program initializes i = 6720 and j = 4. The loop continues while i is divisible by j. Step-by-step execution: 1) 6720 % 4 == 0, so i becomes 1680 and j becomes 5. 2) 1680 % 5 == 0, so i becomes 336 and j becomes 6. 3) 336 % 6 == 0, so i becomes 56 and j becomes 7. 4) 56 % 7 == 0, so i becomes 8 and j becomes 8. 5) 8 % 8 == 0, so i becomes 1 and j becomes 9. 6) 1 % 9 != 0, so the loop terminates. The final value of j is 9.

Explore the full course: Up Lt Grade Assistant Teacher 2025