Problem 12
include
Problem 13
The following program is designed to input two numbers and output their sum.
It asks the user if he/she would like to run the program. If the answer is
\(\mathrm{Y}\) or \(\mathrm{y},\) it prompts the user to enter two numbers. After
adding the numbers and displaying the results, it again asks the user if
he/she would like to add more numbers. However, the program fails to do so.
Correct the program so that it works properly.
#include
Problem 14
What is the output of the following program segment? int count = 0; while (count++ < 10) cout << "This loop can repeat statements." << endl;
Problem 15
What is the output of the following program segment? int count = 5; while (--count > 0) cout << count << " "; cout << endl;
Problem 16
What is the output of the following program segment? int count = 5; while (count-- > 0) cout << count << " "; cout << endl;
Problem 17
What is the output of the following program segment? int count = 1; while (count++ <= 5) cout << count * (count - 2) << " "; cout << endl;
Problem 18
What type of loop, such as counter-control and sentinel-control, will you use in each of the following situations? a. Sum the following series: 1 + (2 / 1) + (3 / 2) + (4 / 3) + (5 / 4) \+ ... + (10 / 9) b. Sum the following numbers, except the last number: 17, 32, 62, 48, 58, -1 c. A file contains an employee’s salary. Update the employee’s salary.
Problem 19
Consider the following for loop: int j, s; s = 0; for (j = 1; j <= 10; j++) s = s + j * (j - 1); In this for loop, identify the loop control variable, the initialization statement, the loop condition, the update statement, and the statement that updates the value of \(\mathbf{s}\)
Problem 20
Given that the following code is correctly inserted into a program, state its entire output as to content and form. (Assume all variables are properly declared.) num = 0; for (i = 1; i <= 4; i++) { num = num + 10 * (i - 1); cout << num << " "; } cout << endl;
Problem 21
Given that the following code is correctly inserted into a program, state its entire output as to content and form. (Assume all variables are properly declared.) j = 2; for (i = 0; i <= 5; i++) { cout << j << " "; j = 2 * j + 3; } cout << j << " " << endl;