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.
@Satbir no, we can observe how condition satisfied and generalize the condition.
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.
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.
64.3k questions
77.9k answers
244k comments
80.0k users