The Gateway to Computer Science Excellence
+5 votes
2.4k views

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

  1. 4
  2. 8
  3. 9
  4. 6720
in Programming by Veteran (105k points) | 2.4k views

3 Answers

+11 votes
Best answer

i=6720, j=4


while ((6720) % 4 ==0)

i = 6720/4 = 1680

j= 4 + 1 = 5


while ( (1680 ) % 5 ==0)

i= 1680 / 5 =336

j = 5 + 1 = 6


while ( (336) %6 ==0)

i= 336 / 6 =56

j = 6+1 = 7


while ((56 %7) ==0)

i = 56/7 = 8

j= 7+1=8


while((8%8==0)

i= 8/8 = 1

j = 8+1 = 9


while ( 1 % 9 ==0)  // false

Ans - j = 9

by Boss (26.5k points)
selected by
+7 votes

6720/4 = 1680 ===> j=5

1680/5 = 336 ===> j=6

336/6 = 56 ===> j=7

56/7 = 8 ===> j=8

8/8 = 1 ===> j=9

Hence final value of j = 9

by Veteran (50.9k points)
+1 vote
answer is 9
by Loyal (9.9k points)
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,324 answers
198,405 comments
105,169 users