...
Programming
October 20, 2023
Programming
October 20, 2023
Programming
October 20, 2023
Programming
October 20, 2023

Programming

Question 287
Consider the following program segment :

d=0;

for(i=1; i<31, ++i)

for(j=1; j<31, ++j)

for(k=1; k<31, ++k)

if ((i+j+k)%3)= = 0);

d = d + 1;

printf(“%d”, d);

The output will be

A
9000
B
3000
C
90
D
2700
Question 287 Explanation: 
Step1: Each for loop will execute 30 times, then total number of iterations are 30*30*30=27000,
But value “d” is incremented only factors of 3 only.
Step2: For the values i=1, j=1 then
k=1,4,7,10,13,16,19,22,25 and 28(10 times)
i=1 and j=2 then
k=3,6,9,12,15,18,21,24,27,and 30(10 times)
i=1 and j=3 then
K=2,5,8,11,14,17,20,23,26,29(10 times)
Then for i=1 value there will be 30*10 =300 times.
Finally for all “i” values from 1 to 30 is
= 300*30
= 9000
Correct Answer: A
Question 287 Explanation: 
Step1: Each for loop will execute 30 times, then total number of iterations are 30*30*30=27000,
But value “d” is incremented only factors of 3 only.
Step2: For the values i=1, j=1 then
k=1,4,7,10,13,16,19,22,25 and 28(10 times)
i=1 and j=2 then
k=3,6,9,12,15,18,21,24,27,and 30(10 times)
i=1 and j=3 then
K=2,5,8,11,14,17,20,23,26,29(10 times)
Then for i=1 value there will be 30*10 =300 times.
Finally for all “i” values from 1 to 30 is
= 300*30
= 9000
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!!