...
Programming-for-Output-Problems
October 6, 2023
Programming-for-Output-Problems
October 6, 2023
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
A
4
B
8
C
9
D
6720
Question 25 Explanation: 
Initial values of i and j are 6720 and 4 respectively
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
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.
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
error: Alert: Content selection is disabled!!