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;
}
1
Expert's answer
2013-05-16T10:44:53-0400
Yes, you are right, answer is "1 3 5". 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 "if (i % 5 = 0)" that holds when i = 0, 5, 10, 15.... So the first value at which the condition is met will be 5, and an indication "break" will stop the loop.
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments