Question

In: Computer Science

Do a walk-through of the following program segments and determine, in each case, the exact output:...

Do a walk-through of the following program segments and determine, in each case, the exact output:

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;

Solutions

Expert Solution

Answer 1:

About • FAQ • Blog • Terms of Use • Contact Us • GDB Tutorial • Credits • Privacy© 2016 - 2019 GDB Online

  Run  Debug  Stop  Share  Save { } Beautify Language                                            -- select --                   C                   C++                   C++ 14                  C++ 17                  Java                  Python 3                  PHP                  C#                  VB                  HTML,JS,CSS                  Ruby                  Perl                  Pascal                  R                  Fortran                  Haskell                  Assembly(GCC)                  Objective C                  SQLite                  Javascript(Rhino)                  Prolog                  Swift                                  Rust                  Go                                  Bash                   

  • main.cpp

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

/******************************************************************************

Online C++ Compiler.

Code, Compile, Run and Debug C++ program online.

Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

int i, j;

for (i = 1; i <= 5; i++)

{

for (j = 1; j <= 5; j++)

cout << setw (3) << i;

cout << endl;

}

return 0;

}

  

  • input

  1  1  1  1  1                                                                                                                                                                                                        

  2  2  2  2  2                                                                                                                                                                                                        

  3  3  3  3  3                                                                                                                                                                                                        

  4  4  4  4  4                                                                                                                                                                                                        

  5  5  5  5  5       

Answer 2:

About • FAQ • Blog • Terms of Use • Contact Us • GDB Tutorial • Credits • Privacy© 2016 - 2019 GDB Online

  Run  Debug  Stop  Share  Save { } Beautify Language                                            -- select --                   C                   C++                   C++ 14                  C++ 17                  Java                  Python 3                  PHP                  C#                  VB                  HTML,JS,CSS                  Ruby                  Perl                  Pascal                  R                  Fortran                  Haskell                  Assembly(GCC)                  Objective C                  SQLite                  Javascript(Rhino)                  Prolog                  Swift                                  Rust                  Go                                  Bash                   

  • main.cpp

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

/******************************************************************************

Online C++ Compiler.

Code, Compile, Run and Debug C++ program online.

Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

int i, j;

for (i = 1; i <= 5; i++)

{

for (j = (i + 1); j <= 5; j++)

cout << setw(5) << j;

cout << endl;

}

return 0;

}

  

  • input

    2    3    4    5                                                                                                                                                                                                   

    3    4    5                                                                                                                                                                                                        

    4    5                                                                                                                                                                                                             

    5                  

Answer 3:

About • FAQ • Blog • Terms of Use • Contact Us • GDB Tutorial • Credits • Privacy© 2016 - 2019 GDB Online

  Run  Debug  Stop  Share  Save { } Beautify Language                                            -- select --                   C                   C++                   C++ 14                  C++ 17                  Java                  Python 3                  PHP                  C#                  VB                  HTML,JS,CSS                  Ruby                  Perl                  Pascal                  R                  Fortran                  Haskell                  Assembly(GCC)                  Objective C                  SQLite                  Javascript(Rhino)                  Prolog                  Swift                                  Rust                  Go                                  Bash                   

  • main.cpp

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

/******************************************************************************

Online C++ Compiler.

Code, Compile, Run and Debug C++ program online.

Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

int i,j;

for (i = 1; i <= 5;i++)

{

for (j = 1; j <= i; j++)

cout << setw(3) << j;

cout << endl;

}

return 0;

}

  

  • input

  1                                                                                                                                                                                                                    

  1  2                                                                                                                                                                                                                 

  1  2  3                                                                                                                                                                                                              

  1  2  3  4                                                                                                                                                                                                           

  1  2  3  4  5                                                                                                                                                                                                        

                                                                                                                                                                                                                       

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

What is the output from each of the following segments of C++ code? Record the output...
What is the output from each of the following segments of C++ code? Record the output after the “Answer” prompt at the end of each program fragment. Assume all variables have been suitably declared. (Each problem is worth 3 points.) 1. for (int j = 8; j > 3; j -= 2)         cout << setw(5) << j;     Answer:      2. int sum = 5;    for (int k = -4; k <= 1; k++)         sum = sum...
Parameter Mystery. Consider the following program. List below the exact output produced by the above program...
Parameter Mystery. Consider the following program. List below the exact output produced by the above program (we do not claim that every line of output makes sense ;-). public class Mystery { public static void main(String[] args) { String john = "skip"; String mary = "george"; String george = "mary"; String fun = "drive"; statement(george, mary, john); statement(fun, "george", "work"); statement(mary, john, fun); statement(george, "john", "dance"); } public static void statement(String mary, String john, String fun) { System.out.println(john + "...
For the following program segments, write a program that shows the estimated runtime for each piece....
For the following program segments, write a program that shows the estimated runtime for each piece. Run it on your computer when n=1, 10, 100, 1000, 10000, 100000, 1000000 for ten times each so that you can observe the differences in performance among these segments. Segment1:        for (sum=0, i=1; i<=n; i++)                         sum = sum + i; Segment2:        for (sum=0, i=1; i<=n; i++)                                                 for (j=1; j<=i; j++)                                                             sum++; Segment3:        sum= n * (n+1)/2
Check if each of the following ODEs is an exact. If it is not an exact...
Check if each of the following ODEs is an exact. If it is not an exact find an integrating factor to make it an exact. Then solve each of the following ODEs. (e) dx + (x/y−siny)dy = 0 (f) ydx + (2x−yey)dy = 0 (g) (3x2y + 2xy + y3)dx + (x2 + y2)dy = 0
In JAVA answer has to be able to do exact Sample Output shown Write a do-while...
In JAVA answer has to be able to do exact Sample Output shown Write a do-while loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The loop should ask the user whether he or she wishes to perform the operation again. If so, the loop should repeat; otherwise it should terminate. Name your class as NumberSum and add to it your header and sample output as a block comments. Upload the...
Illustrate each of the following scenarios. In each case, assume that the corresponding output market is...
Illustrate each of the following scenarios. In each case, assume that the corresponding output market is competitive. a. Equilibrium in a perfectly competitive labor market (be sure to draw both a market and a firm graph). b. Equilibrium in a monopsony labor market. c. Equilibrium in a monopoly labor market (for example, a labor market with a union maximizing economic rent).
Use the Excel output in the below table to do (1) through (6) for each ofβ0,...
Use the Excel output in the below table to do (1) through (6) for each ofβ0, β1, β2, and β3. y = β0 + β1x1 + β2x2 + β3x3 + ε     df = n – (k + 1) = 16 – (3 + 1) = 12 Excel output for the hospital labor needs case (sample size: n = 16) Coefficients Standard Error t Stat p-value Lower 95% Upper 95% Intercept 1946.8020 504.1819 3.8613 0.0023 848.2840 3045.3201 XRay (x1) 0.0386...
PROBLEM: Write a C program that will produce the EXACT output shown below. Using initialization lists,...
PROBLEM: Write a C program that will produce the EXACT output shown below. Using initialization lists, create 5 one-dimensional arrays, one for each of these: hold the names of the people running in the election (see note below) hold the names of the subdivision (see note below) hold the vote counts in the Aberdeen subdivision for each candidate hold the vote counts in the Brock subdivision for each candidate hold the vote counts in the Sahali subdivision for each candidate...
Determine the missing amounts in each of the following independent cases. Case A Case B Case...
Determine the missing amounts in each of the following independent cases. Case A Case B Case C Beginning inventory, raw material 98,000 7,500 Ending inventory, raw material 199,000 34,000 Purchases of raw material 295,000 274,000 Direct material used 235,000 323,000 Direct labor 395,000 72,000 Manufacturing overhead 595,000 99,000 Total manufacturing costs 1,135,000 1,130,000 222,000 Beginning inventory, work in process 89,000 79,000 Ending inventory, work in process 124,000 4,400 Cost of goods manufactured 1,088,000 225,000 Beginning inventory, finished goods 195,000 139,000...
Determine the missing amounts in each of the following independent cases Case A Case B Case...
Determine the missing amounts in each of the following independent cases Case A Case B Case C Beginning inventory, raw material $ ------- $ 68,000 $ 45,000 Ending inventory, raw material 184,000 ----- 19,000 Purchases of raw material 220,000 259,000 ------ Direct material used 160,000 259,000 ------- Direct labor ------ 320,000 64,500 Manufacturing overhead 520,000 ------ 84,000 Total manufacturing costs 1,060,000 1,055,000 190,000 Beginning inventory, work in process 74,000 64,000 ----- Ending inventory, work in process ----- 109,000 2,900 Cost...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT