What is sum after the following loop terminates?
int sum = 0;
int item = 0;
do {
item++;
sum += item;
if (sum > 4)
break;
}
while (item < 5);
a. 5
b. 6
c. 7
d. 8
e. 9
b sum and item are initialized to 0 before the loop. In the loop, item++ increments item by 1 and item is then added to sum. If sum > 4, the break statement exits the loop. item is initially 0, then 1, 2, 3 and sum is initially 0, and then 1, 3, and 6 . When sum is 6, (sum > 4) is true, which causes the break statement to be executed. So, the correct answer is B.
You might also like to view...
Will my program compile, link, and run if I have the prototype but not the function body? Will it compile, link, and run if I have the function body but not the prototype? Prototype and call, but no function body? Call, function body, but no prototype?
What will be an ideal response?
Constructing a large program from smaller components is called _______ .
Fill in the blank(s) with the appropriate word(s).
Describe the changes that occur when a workstation joins a domain.
What will be an ideal response?
UNIVAC is considered the first working, digital, general-purpose computer
Indicate whether the statement is true or false