Show what the following loop will display. Be careful. Assume
no previous output.
Answers at the bottom.
int num = 1;
while (num <= 8)
{
switch (num)
{
case 2: cout << "Bill\n";
case 4: cout << "Mary\n";
break;
case 6: cout << "Anne\n";
case 7: cout << "Fred\n";
break;
default: cout << "Whoops\n";
}
num++;
}
Show what the following loops will display. Be careful. Assume no previous output.
int row;
int column;
for (row = 1; row <= 4; row++)
{
for (column = row; column >= 1; column--)
{
cout <<
column << ' ';
}
cout << row << endl;
}
Answers:
Whoops
1 1
Billy
2 1 2
Mary
3 2 1 3
Whoops
4 3 2 1 4
Mary
Whoops
Anne
Fred
Fred
Whoops