0

for(int i=2;i<20;i++) { for(int j=2; j<=(i/j);j++) { if(!(i%j)) break; f(j>(i/j)) cout<<i<"\n"; } }

How many time this program will run?

5th May 2021, 4:12 AM
Tannia Devi
Tannia Devi - avatar
5 Respostas
+ 3
Try it in code playground.
5th May 2021, 4:26 AM
Hrutik Bhalerao
Hrutik Bhalerao - avatar
+ 2
Assuming you fix the typos, the loops will run 31 times. Not all 31 values get printed though
5th May 2021, 4:27 AM
Chris
Chris - avatar
+ 1
Kruti the way he has his brackets is perfectly fine. What you are referring to is going conventions. Unwritten rules that should be followed, but aren't vital. You can do them either way and it will function the same way. This: for (con) { ...; } can work the same as: (in OP's code) for (con) { ...; } or even this (I do this sometimes if there is only 1 instruction in the for loop): for (con) { ...; }
5th May 2021, 5:16 PM
Chris
Chris - avatar
+ 1
Oh okay... Thanks Chris!
5th May 2021, 5:18 PM
Kruti
Kruti - avatar
0
Well, the the brackets are wrong. It is for (condition) { statement ; }
5th May 2021, 5:10 PM
Kruti
Kruti - avatar