3 3 votes 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. 6 20 33 none of these Programming in C iiith-pgee loop counting programming + – manikgupta123 4.6k views answer comment Share Follow Print See all 26 Comments 26 26 Comments reply srestha commented Apr 29, 2019 reply Follow flag 20 times 0 0 replyShare Lakshman Bhaiya commented Apr 29, 2019 reply Follow flag @srestha ma'am can you explain? 0 0 replyShare srestha commented Apr 29, 2019 reply Follow flag @Lakshman Patel RJIT u answer it, I will correct it, if u do any mistake :) is it ok?:) 0 0 replyShare Lakshman Bhaiya commented Apr 29, 2019 i edited by Lakshman Bhaiya Apr 29, 2019 reply Follow flag when $i=0$ we print $\text{"GreatIndia"}$ 0 0 replyShare srestha commented Apr 29, 2019 reply Follow flag 1. i=0. //initialization 2.i % 3 == 0 // Condition checking, and condition is true 3. Print "Great" 4. i%5 == 0 // Condition checking, and condition is true 5. Print "India" Now, 1. i=1. //initialization 2.i % 3 == 0 //Condition checking , and condition is false 4. i%5 == 0 // Condition checking, and condition is False Nothing Printed. Similar for i=2 Same as above Nothing printed here too 1. i=3. //initialization 2.i % 3 == 0 // Condition checking, and condition is true 3. Print "Great" 4. i%5 == 0 // Condition checking, and condition is False 5. Not Print "India" i=4 no. condition will be true // same as i=2 1. i=5. //initialization 2.i % 3 == 0 // Condition checking, and condition is False 3. Not Print "Great" 4. i%5 == 0 // Condition checking, and condition is true 5. Print "India" Now, Similarly i=6 will Print "Great" But here not getting India Again for i=9 will print "Great" i=10 will get "India" Similarly if we calculate in i=15 , we get total 3 "Great India" So, from this we can say , in i=90, we get 18 "Great India" Now, from 90 to 100 we get 2 more Great India So, total 20 3 3 replyShare srestha commented Apr 29, 2019 reply Follow flag you have to check line by line Donot combine the lines 1 1 replyShare Lakshman Bhaiya commented Apr 29, 2019 reply Follow flag Yes ma'am But i got $21$ see my above comment 1 1 replyShare srestha commented Apr 29, 2019 reply Follow flag yes, 21 So, ans D) right? 2 2 replyShare Lakshman Bhaiya commented Apr 29, 2019 reply Follow flag I check three times and I got $21$,so I think $(D)$ is the correct answer. 0 0 replyShare Lakshman Bhaiya commented Apr 29, 2019 i edited by Lakshman Bhaiya Apr 29, 2019 reply Follow flag @Arjun sir please check this If we write like this int main() { for(int i=0; i<=100;i++) { if (i % 3 == 0 && i%5 == 0) { printf("GreatIndia"); } } return 0; } Divisible by $3$ and divisible by $5$ means divisible by $\text{LCM(3,5)=15}$ ${\color{Green}{i=0,15,30,45,60,75,90} }$ We print ${\color{Magenta} {\text{GreatIndia}}}$ $7$ times. If we write like this int main() { for(int i=0; i<=100;i++) { if (i % 3 == 0 || i%5 == 0) { printf("GreatIndia"); } } return 0; } Divisible by $3$ (or) divisible by $5$ For $i=0$ we print ${\color{DarkOrange}{"GreatIndia"} }$ and from ${\color{Purple} {i=1,2,3,...,100}}$ we can apply principle of mutual inclusion and exclusion ${\color{Magenta} {|A\cup B|=|A|+|B|-|A\cap B|}}$ Here $A=3,B=5$ $|3\cup 5| = |3| + |5| - |3\cap 5|$--------->$(1)$ Now,$|3| =\left \lfloor \frac{100}{3} \right \rfloor=33$ $|5|=\left \lfloor \frac{100}{5} \right \rfloor=20$ $|3\cap 5|=\left \lfloor \frac{100}{LCM(3,5)} \right \rfloor=\left \lfloor \frac{100}{15} \right \rfloor=6$ Put all values in equation $(1)$ and we can $|3\cup 5|=33+20-6=53-6=47$ So total we can print $1+47=48$ We print ${\color{Red} {\text{GreatIndia}}}$ $48$ times. But given question in a different way So,we print like this $i=0,0$---->(1) $i=3,5$--->(2) $i=9,10$----->(3) $i=15,15$----->(4) $i=18,20$---->(5) $i=24,25$---->(6) $i=30,30$---->(7) $i=33,35$---->(8) $i=39,40$---->(9) $i=45,45$---->(10) $i=48,50$---->(11) $i=51,55$---->(12) $i=60,60$---->(13) $i=63,65$---->(14) $i=69,70$---->(15) $i=75,75$---->(16) $i=78,80$---->(17) $i=84,85$---->(18) $i=90,90$---->(19) $i=93,95$---->(20) $i=99,100$---->(21) Why i neglect i = 12 case? When $i=12$ it is divisible by $3$ So it print ${\color{Red}{\text{Great}} }$ But after that $i$ become $15$ then it is divisible by $3$ as well as $5$ So,it will print ${\color{DarkOrange}{\text{GreatIndia}} }$ So, finally answer is $21$ 3 3 replyShare SuvasishDutta commented Apr 30, 2019 reply Follow flag Yes option d is the correct answer 0 0 replyShare Arkaprava commented May 7, 2019 i moved by Lakshman Bhaiya May 8, 2019 reply Follow flag Possible values of i are { 0,15,30,45,60,75,90} , i.e there are 7 values where "GreatIndia" is printed. So D is the answer. 0 0 replyShare Lakshman Bhaiya commented May 8, 2019 reply Follow flag @Arkaprava please see my above comment. Answer must be $21$ When you don't explain the answer please write in the comment section. 0 0 replyShare Arkaprava commented May 8, 2019 reply Follow flag Ok i realised the flaw now. 0 0 replyShare Kaluti commented May 22, 2019 reply Follow flag answer should be 7 multiple of 15 are found 0 0 replyShare Lakshman Bhaiya commented May 22, 2019 reply Follow flag @Kaluti the answer should be $21$, please solve again. 0 0 replyShare Kaluti commented May 23, 2019 reply Follow flag Okay it means I have to take every possible combination of multiple of 3 and 5 here 0 0 replyShare Kaluti commented May 23, 2019 reply Follow flag For I = 0 nothing will be will be printed 0 0 replyShare Lakshman Bhaiya commented May 23, 2019 reply Follow flag $i=0$ "GreatIndia" will be printed. 0 0 replyShare Satbir commented May 23, 2019 reply Follow flag For i=0 great india will be printed. 0 0 replyShare Kaluti commented May 23, 2019 reply Follow flag how 0 mod 3 wouldn't be equal to zero 0 0 replyShare Satbir commented May 23, 2019 reply Follow flag 0 mod 3 means remainder when we divide 0 by 3 so it is 0 0 0 replyShare Kaluti commented May 23, 2019 reply Follow flag Okay got confused it's zero is divided by three not the other way 0 0 replyShare Satbir commented May 23, 2019 reply Follow flag if this question comes in gate then we will execute the loop step by step for 100 times ? 1 1 replyShare Lakshman Bhaiya commented May 23, 2019 reply Follow flag @Satbir no, we can observe how condition satisfied and generalize the condition. 0 0 replyShare dexter_n commented Feb 18, 2021 reply Follow flag C program I think correct answer would be 7 option (D) Here, In above c program; I have used variable c which will increment if i is divisible by 3 and 5 both so it will print both “GREAT INDIA” together; and whenever c==2 that means both if loops gets executed post that used ‘d’ variable to count how many times this has happened. so final answer =7 Please cross check question once; if outer for loop would have started with i=1 then answer would be 6 because 0 is excluded in that case. 0 0 replyShare Please log in or register to add a comment.
3 3 votes 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 satya753 answered Aug 25, 2019 satya753 comment Share Follow 0 reply Please log in or register to add a comment.
2 2 votes The answer should be 21. From 0 to 100; "GreatIndia" be printed at the following: a) All multiples of 15 ( 7 times) b) Every time a multiple of 5 which is not a multiple of 15 is encountered after a multiple of 3, which again should not be a multiple of 15. For eg at i=3 and then at i=5. Then at i=9 and i=10. The last one will be at i=99 and i=100. Now from 1 to 15, GreatIndia is printed 3 times. So from 16 to 90 it will be printed another 15 times. From i=91 to i=100, GreatIndia will be printed after i=93 and i=95. The last one will be at i=99 and i=100. And the very first one is at i=0. Adding up, we have GreatIndia printed 21 times. You can also run the code and check. Put a newline after printf("India") statement for ease in counting. Chinmay Agnihotri answered May 8, 2020 • edited May 8, 2020 by Chinmay Agnihotri Chinmay Agnihotri comment Share Follow 0 reply Please log in or register to add a comment.
1 1 vote Answer : D, 7 times for the following values of i 0, 15, 30, 45, 60, 75, 90 lalitkumar0014 answered Aug 28, 2019 lalitkumar0014 comment Share Follow 0 reply Please log in or register to add a comment.