What is sum after the following loop terminates? int sum = 0; int item = 0; do {
ID: 3692437 • Letter: W
Question
What is sum after the following loop terminates?
int sum = 0;
int item = 0;
do
{
item++;
sum += item;
if (sum >= 4) continue;
}
while (item < 5);
16
15
18
17
Will the following program terminate?
int balance = 10;
while (true)
{
if (balance < 9) break;
balance = balance - 9;
}
Yes
No
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);
7
6
8
5
Question 21
What is the number of iterations in the following loop:
for (int i = 1; i <= n; i++)
{
// iteration
}
n - 1
n + 1
n
2*n
16
15
18
17
Will the following program terminate?
int balance = 10;
while (true)
{
if (balance < 9) break;
balance = balance - 9;
}
Yes
No
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);
7
6
8
5
Question 21
What is the number of iterations in the following loop:
for (int i = 1; i <= n; i++)
{
// iteration
}
n - 1
n + 1
n
2*n
Explanation / Answer
After the loop terminates, sum = 15.
Yes, the program will terminate after 1 iteration.
After the program terminates, sum = 6.
The number of iterations in the for loop is n.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.