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?
5 Respostas
+ 3
Try it in code playground.
+ 2
Assuming you fix the typos, the loops will run 31 times. Not all 31 values get printed though
+ 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) { ...; }
+ 1
Oh okay... Thanks Chris!
0
Well, the the brackets are wrong. It is
for (condition) {
statement ;
}