Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Problem 12

include using namespace std; int main() { int num;… # Suppose that the input is: 58 23 46 75 98 150 12 176 145 -999 What is the output of the following program? #include using namespace std; int main() { int num; cin >> num; while (num != -999) { cout << num % 25 << " "; cin >> num; } cout << endl; return 0; }

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 #include using namespace std; int main() { char response; double num1; double num2; cout << "This program adds two numbers." << endl; cout << "Would you like to run the program: (Y/y) "; cin >> response; cout << endl; cout << fixed << showpoint << setprecision(2); while (response == 'Y' && response == 'y') { cout << "Enter two numbers: "; cin >> num1 >> num2; cout << endl; cout << num1 << " + " << num2 << " = " << (num1 - num2) << endl; cout << "Would you like to add again: (Y/y) "; cin >> response; cout << endl; } return 0; }

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;

Access millions of textbook solutions in one place

  • Access over 3 million high quality textbook solutions
  • Access our popular flashcard, quiz, mock-exam and notes features
  • Access our smart AI features to upgrade your learning
Get Vaia Premium now
Access millions of textbook solutions in one place

Recommended explanations on Computer Science Textbooks