The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
x
+3 votes
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
in Programming by (81 points)
edited by | 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.

2 Answers

+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)
0 votes
Answer : D,

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

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,376 questions
55,840 answers
192,571 comments
91,396 users