###### Programming-for-Output-Problems

October 6, 2023###### Programming-for-Output-Problems

October 6, 2023# Programming-for-Output-Problems

Question 25 |

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

i=6720;

j=4;

while (i%j==0)

{

i=i/j;

j=j+1;

}

On termination j will have the value

4 | |

8 | |

9 | |

6720 |

Question 25 Explanation:

Initial values of i and j are 6720 and 4 respectively

i=6720

j=4

i%j==0 which is 6720%4 ==0 condition is true then

i=i/j=6720/4=1680

j=j+1=5

i=1630

j=5

i%j==0 which is 1680%5 ==0 condition is true then

i=i/j=1630/5=336

j=j+1=6

i=336

j=6

i%j==0 which is 336%6 ==0 condition is true then

i=i/j=336/6=56

j=j+1=7

i=56

j=7

i%j==0 which is 56%7 ==0 condition is true then

i=i/j=56/7=8

j=j+1=8

i=8

j=8

i%j==0 which is 8%8 ==0 condition is true then

i=i/j=8/8=1

j=j+1=9

i=1

j=9

i%j==0 which is 1%9 ==0 condition is false.

At this iteration, the “j” value is 9.

__Iteration 1:__i=6720

j=4

i%j==0 which is 6720%4 ==0 condition is true then

i=i/j=6720/4=1680

j=j+1=5

__Iteration-2:__i=1630

j=5

i%j==0 which is 1680%5 ==0 condition is true then

i=i/j=1630/5=336

j=j+1=6

__Iteration-3:__i=336

j=6

i%j==0 which is 336%6 ==0 condition is true then

i=i/j=336/6=56

j=j+1=7

__Iteration-4:__i=56

j=7

i%j==0 which is 56%7 ==0 condition is true then

i=i/j=56/7=8

j=j+1=8

__Iteration-5:__i=8

j=8

i%j==0 which is 8%8 ==0 condition is true then

i=i/j=8/8=1

j=j+1=9

__Iteration-6:__i=1

j=9

i%j==0 which is 1%9 ==0 condition is false.

At this iteration, the “j” value is 9.

Correct Answer: C

Question 25 Explanation:

Initial values of i and j are 6720 and 4 respectively

i=6720

j=4

i%j==0 which is 6720%4 ==0 condition is true then

i=i/j=6720/4=1680

j=j+1=5

i=1630

j=5

i%j==0 which is 1680%5 ==0 condition is true then

i=i/j=1630/5=336

j=j+1=6

i=336

j=6

i%j==0 which is 336%6 ==0 condition is true then

i=i/j=336/6=56

j=j+1=7

i=56

j=7

i%j==0 which is 56%7 ==0 condition is true then

i=i/j=56/7=8

j=j+1=8

i=8

j=8

i%j==0 which is 8%8 ==0 condition is true then

i=i/j=8/8=1

j=j+1=9

i=1

j=9

i%j==0 which is 1%9 ==0 condition is false.

At this iteration, the “j” value is 9.

__Iteration 1:__i=6720

j=4

i%j==0 which is 6720%4 ==0 condition is true then

i=i/j=6720/4=1680

j=j+1=5

__Iteration-2:__i=1630

j=5

i%j==0 which is 1680%5 ==0 condition is true then

i=i/j=1630/5=336

j=j+1=6

__Iteration-3:__i=336

j=6

i%j==0 which is 336%6 ==0 condition is true then

i=i/j=336/6=56

j=j+1=7

__Iteration-4:__i=56

j=7

i%j==0 which is 56%7 ==0 condition is true then

i=i/j=56/7=8

j=j+1=8

__Iteration-5:__i=8

j=8

i%j==0 which is 8%8 ==0 condition is true then

i=i/j=8/8=1

j=j+1=9

__Iteration-6:__i=1

j=9

i%j==0 which is 1%9 ==0 condition is false.

At this iteration, the “j” value is 9.

Subscribe

Login

0 Comments