64 638
Assignments Done
99,2%
Successfully Done
In September 2018

Answer to Question #29922 in C++ for jeff

Question #29922
hi i am looking for help on this i think the answer is: 1, 3, 5. Any help would be great.

for(int i = 1; i < 10; i+=2)
{
cout<< i <<endl;
if( i % 5 == 0)
break;
}
Expert's answer
Yes, you are right, answer is &quot;1 3 5&quot;. Theinitial value of the i variable is 1. and each step it is incremented by 2, so it will
be (2n+1) on the nth step. So loop will just print odd numbers: 1, 3, 5, 7, 9...But there is condition &quot;if (i % 5 = 0)&quot; that holds when i = 0, 5,
10, 15.... So the first value at which the condition is met will be 5, and an
indication &quot;break&quot; will stop the loop.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions