Question
Can you please help me answer this six questions? 1 )Suppose that the input is 3 4 6 7 2 -1. What is the output
Can you please help me answer this six questions?
1)Suppose that the input is 3 4 6 7 2 -1. What is the output of the following code? (2, 3) int num; int sum; cin >> num; sum = num; while (num != -1) { sum = sum + 2 * num; cin >> num; } cout << "Sum = " << sum << endl;
2)Suppose that the input is 10 -6 12 -5 -4 0. What is the output of the following code? (2, 3) int num; int sum = 0; cin >> num; while (num != 0) { if (num > 0) sum = sum + num; else sum = sum - num; cin >> num; } cout << "Sum = " << sum << endl;
3)Suppose that the input is: 58 23 46 75 98 150 12 176 145 -999 What is the output of the following program? (2, 3) #include
int main() { int num; int count = 0; cin >> num; while (num != -999) { count++; cout << num % count << " "; cin >> num; } cout << endl; return 0; }
4)What type of loop, such as counter-control or sentinel-control, will you use in each of the following situations? (3) a. Sum the following series: 1 + (2 / 1) + (3 / 2) + (4 / 3) + (5 / 4) + ... + (10 / 9) b. Sumthe following numbers, except the last number: 17, 32, 62, 48, 58, -1 c. A file contains an employees salary. Update the employees salary.
5)The following program contains errors that prevent it from compiling and/ or running. Correct all such errors. (4) #include
6) To learn how nested for loops work, do a walk-through of the following program segments and determine, in each case, the exact output. (4, 7) a. int i, j; for (i = 1; i <= 5; i++) { for (j = 1; j <= 5; j++) cout << setw(3) << i; cout << endl; } b. int i, j; for (i = 1; i <= 5; i++) { for (j = (i + 1); j <= 5; j++) cout << setw(5) << j; cout << endl; } c. int i, j; for (i = 1; i <= 5; i++) { for (j = 1; j <= i; j++) cout << setw(3) << j; cout << endl; } d. const int M = 10; const int N = 10; int i, j; for (i = 1; i <= M; i++) { for (j = 1; j <= N; j++) cout << setw(3) << M * (i - 1) + j; cout << endl; } e. int i, j; for (i = 1; i <= 9; i++) { for (j = 1; j <= (9 - i); j++) cout << " "; for (j = 1; j <= i; j++) cout << setw(1) << j; for (j = (i - 1); j >= 1; j--) cout << setw(1) << j; cout << endl; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started