| CMPSC 101 - Loops Worksheet #1 | Name - |
1. In the right margin, show what output would be displayed by the following program.
#include <iostream>
using namespace std;int main()
{
int i = 0, j = 1, k = 0, m = 4;
for (i = 0; i < 10; i++)
{
cout << i << endl;
}
for (j = 13; j > 0; j = j - 2)
{
cout << j << endl;
}
for (k = 2; k < m * 2; k++)
{
cout << k << endl;
if (k > 6)
{
break;
}
}
return 0;
}
2. In the right margin, show what output would be displayed by the following program.
#include <iostream>
using namespace std;int main( )
{
int number = 10;
int another = 90;
while (number > 4)
{
number = number - 2;
cout << number - 2 << endl;
}another = 1;
do
{
another = another * 2;
cout << another << endl;
}while (another < 100 && another > 1);
return 0;
}
3. Write a for loop that will display the sequence of numbers 3, 6, 9, 12, 15, .... , 33 on separate lines.