253 views
for(int i=0; i<=100;i++) {
if (i % 3 == 0)
printf("Great);
if(i%5 == 0)
printf("India");
}

Count the number of times GreatIndia is printed.

1. 6
2. 20
3. 33
4. none of these

edited | 253 views
0

the answer should be $21$, please solve again.

0
Okay it means I have to take every possible combination of multiple of 3 and 5 here
0
For I = 0 nothing will be will be printed
0
$i=0$

"GreatIndia" will be printed.
0
For i=0 great india will be printed.
0
how 0 mod 3 wouldn't be equal to zero
0
0 mod 3 means remainder when we divide 0 by 3 so it is 0
0
Okay got confused it's zero is divided by three not the other way
0
if this question comes in gate then we will execute the loop step by step for 100 times ?
0

@ no, we can observe how condition satisfied and generalize the condition.

+1 vote
It would print exactly 7 times.

We have to find total integers divisible by 3 and 5 between 0 and 100 there are 7 integers divisible by 3 and 5

i.e 0 , 15 , 30  , 45 , 60 , 75 , 90
by (103 points)

7 times
for the following values of i
0, 15, 30, 45, 60, 75, 90
by (21 points)

1
+1 vote