Quiz with loop from 0 to 100 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Quiz with loop from 0 to 100

I take 1 hour to get the result for loop 100 time, it is not programming !!!!!!

10th Jun 2017, 10:48 PM
Chokri ZAGROUBA
Chokri ZAGROUBA - avatar
8 Answers
+ 10
for (int i = 0; i < 100; i++) { //codes } ?
11th Jun 2017, 4:54 AM
Hatsy Rei
Hatsy Rei - avatar
+ 9
@Chokri It would print all even numbers between 0 and 99
11th Jun 2017, 1:42 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
Thank you for your remarks and answers. But I think that we can skip this type (loops with N>10 ) of quiz.
11th Jun 2017, 4:32 PM
Chokri ZAGROUBA
Chokri ZAGROUBA - avatar
+ 1
c++
11th Jun 2017, 2:59 AM
Chokri ZAGROUBA
Chokri ZAGROUBA - avatar
+ 1
like this , what is the output in 15sec: for(int i=0;i<99;i++) { if (i%2 == 0) cout << i; }
11th Jun 2017, 7:15 AM
Chokri ZAGROUBA
Chokri ZAGROUBA - avatar
+ 1
I would say "between 0 and 98" but there are not real difference in this case 'cause 99 anyway is not an even number (but loop won't run with i=99). Just wanted to mind it for those who has just started.
11th Jun 2017, 3:57 PM
Andrew Harchenko (Tomsk)
Andrew Harchenko (Tomsk) - avatar
+ 1
@Chokri ZAGROBA every time the loop runs it checks if i%2==0 which happens(=means) "if i is even" then... and then goes output cout << i; so this code outputs every even number as Hatsy Rei has said. And then, I'm sure as... just very sure, question don't ask you to enter each number in output. :-) It could ask what is the last number in output (it's 98), how many numbers is printed (it's 50). And (sorry, but) all of this are easy questions that don't need you to iterate through it step by step. But sometimes there are questions with loops that needs you to iterate through some ten steps and usually those question are very hard to solve in given time. I'm still not sure if we should to collect such issues, discuss them here in Q/A sections, and then report some of them.
11th Jun 2017, 4:06 PM
Andrew Harchenko (Tomsk)
Andrew Harchenko (Tomsk) - avatar
0
What language?
11th Jun 2017, 2:21 AM
Jason Runkle
Jason Runkle - avatar