Consider the following program fragment
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. | 9030 |
B. | 27000 |
C. | 3000 |
D. | none of the above |
Answer : A Explanation : a + b +c 3 will be 0 if a + b+c is a multiple of 3. This will happen in one of the following ways. All three - a, b, and c are multiples of 3. This can only happen if a, b, and c take one of the 10 values. - 3 , 6, 9 , ..... , 30, independent of one another. So, there are 10 x 10 x 10 = 1000 ways this can happen. Another possibility is that a, b, and c all leave a remainder 1 so that a + b + c is evenly divisible by 3. Considering all the different possibilities and adding. we get 9000. That will be the integer that gets printed. |
|
Option: A Explanation : Explanation will come here. Explanation will come here. Explanation will come here. Explanation will come here. Explanation will come here. |