In questions 7 to 17, determine the output generated by the respective program segment.
Assume that the appropriate header files have been included.
7.
int A = 1;
while (17 % A != 5)
{
cout << A << " " << 17 % A <<endl;
++A;
} //END WHILE
8.
int B = 2;
do
{
cout << B << " " << B / 5 <<endl;
B *= 2;
} //END DO/WHILE
while (B != 20);
9.
int B = 2;
do
{
cout << B << " " << B / 5 <<endl;
B *= 2;
} //END DO/WHILE
while (B != 32);
10.
int number = 1;
int product = 1;
do
{
++number;
product *= number;
} //END DO/WHILE
while (number < 5);
cout << "The product is: " << product <<endl;
11.
| int
count = -3; while (count < 3) { if (count == 0 ) continue; cout << count << '\t'; ++count; } // END WHILE |
int
count = -3; while (++count < 3) { if (count == 0 ) continue; cout << count << '\t'; } // END WHILE |
12.
int count = -3;
while (count < 3)
{
++count;
if(count == 0)
continue;
cout << count << '\t';
} //END WHILE
13.
int count = -3;
while (count < 3)
{
++count;
if(count == 0)
break;
cout << count << '\t';
} //END WHILE
14.
cout << "Angle\tSin\tCos" <<endl;
cout << "-----\t---\t---" <<endl;
const double PI = 3.14159;
cout.setf(ios::fixed);
cout.precision(3);
for (int angle = 0; angle < 91; angle += 5)
cout << angle << '\t' << sin(angle * PI /180)
<< '\t' << cos(angle * PI /180) <<endl;
15.
for ( int row = 1; row < 6; ++row)
{
for ( int col = 1; col < 11 ; ++col)
cout << row <<',' << col << '\t';
cout <<endl;
} //END FOR
16.
int count = 0;
const int MAXCOUNT = 5;
while (count < MAXCOUNT)
{
for (int i = 1; i < MAXCOUNT + 1; ++i)
cout << i;
cout <<endl;
++count;
} //END WHILE
17.
int const MAXCOUNT = 5;
int times = 3;
do
{
int count = 0;
while (count < MAXCOUNT)
{
for ( int j = 1; j < count + 1; ++j)
cout << j;
++count;
cout << endl;
}//END WHILE
cout <<endl;
-- times;
} //END DO?WHILE
while (times != 0);
18. When will the following loop terminate?
bool flag = true; //DEFINE BOOLEAN VARIABLE
//ASSUMES ANSI/ISO STANDARD
int number = 0; //INPUT VARIABLE
int sum = 0; //SUM VARIABLE
char query = 'N'; //CONTINUE QUERY
while (flag == true)
{
cout << "Enter an integer value: ";
cin >> number;
cout << "Want to continue (y/n)?" << endl;
cin >> query;
if ((query == 'n') || (query == 'N'))
{
flag = false;
cout << "Loop terminated" << endl;
}//END IF
else
{
sum = sum + number;
cout << "The sum is now " << sum <<endl;
}//END ELSE
} //END WHILE