Question

In: Computer Science

Trace the following code segment 1. use the red numbers under each statement to show the...

Trace the following code segment

1. use the red numbers under each statement to show the order that you execute the code by.

For example: (1) means int p=3; (2) means p<10; (3) means p+=3;

(1)(2)(3) means you execute int p=3 then p<10 then P+=3;

(2)(1)(3) means you execute p<10 then int p =3 then P+=3;

2. show its output

for (int p = 3 ; p <10; p += 3 )

   (1) (2) (3)       

  {   

for ( int m = 3 ; m < 6 ; m++)

   (4) (5) (6)

                  cout<<    (p * m) <<      “      “;

  (7)

       cout << “$”    <<     endl;

  (8)

}

  

Solutions

Expert Solution

Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate the question. Thank You So Much.

execution will be as below

Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate the question. Thank You So Much.

(1) // first p will set to 3
(2)       // Now it will check if p<10
(4)       // Now it will go to m=3
(5)       // now it will check if m<6
(7)       // than it will execute p*m
(6)       // now it will execute m++
(5)       // again it will check if m<6
(7) // than it will execute p*m
(6)    //now this pattern wil be repeat unitl m<6
(5)
(7)
(6)
(5) // now condition will be false
(8) // nwo cout $ will execute
(3)   // now it will call p+=3
(2) // now it will check if p<10
(4) // again it will repeat inner loop just like above
(5)
(7)
(6)
(5)
(7)
(6)
(5)
(7)
(6)
(5)
(8)
(3)
(2)
(4)
(5)
(7)
(6)
(5)
(7)
(6)
(5)
(7)
(6)
(5)
(8)   
(3) //again it will execute p+=3
(2)       //now condition willl be false

2)

As per the execution explained above, Result will be


Related Solutions

Trace the following code segment 1. use the red numbers under each statement to show the...
Trace the following code segment 1. use the red numbers under each statement to show the order that you execute the code by. For example: (1) means int p=3; (2) means p<10; (3) means p+=3; (1)(2)(3) means you execute int p=3 then p<10 then P+=3; (2)(1)(3) means you execute p<10 then int p =3 then P+=3; 2. show its output: int x = 30,  num = 100;     (1)    while ( x > 0) (2)           { cout   <<   endl                          <<  “ x...
What is the Θ( ) for each code segment below? (a) for( int i = 1,...
What is the Θ( ) for each code segment below? (a) for( int i = 1, i<= n, i = i*2){       some constant operation } (b) for( int i = 1, i<= n, i++){      for( int j = 2*i, j<=n, j++){           some constant operation      } } (c) for( int i = 1, i<= n, i = i*2){      for( int j = 1, j<=n, j = j*2){           some constant operation      } }
2. Show the trace of the RTL code for Booth's algorithm for X = 0111 and...
2. Show the trace of the RTL code for Booth's algorithm for X = 0111 and Y = 1011.
Given the following numbers in the given order, show the red black tree              100, 200,...
Given the following numbers in the given order, show the red black tree              100, 200, 150, 170, 165, 180, 220, 163, 164 Show the pre-order traversal of this red black tree while showing the color of each node in the pre-order traversal. Write (C++) the red black tree code and insert the above numbers. Show the screen shot of the pre-order traversal of the resulting tree. Distinguish the colors by writing a * next to the black color values....
Show the output of the following code segment. int count=0;                         for (int i=2; i <=...
Show the output of the following code segment. int count=0;                         for (int i=2; i <= 4; i++ ) {                                     StdOut.println(i);                                     for (int j=1; j <3; j++) {                                                 count++;                                                 StdOut.println(i +" " + j +" "+ count);                                     }                         } count i j I print 0 2 1 3 1 1 1 2 3 2 2 3 3 3 3 4 3 Show the output of the function call statements shown.             double x =...
1. What will be the value of numbers[1] after the following code is executed? int[] numbers...
1. What will be the value of numbers[1] after the following code is executed? int[] numbers = {22, 33, 44}; for(int k = 0; k < 3; k++) { numbers[k] = numbers[k] + 5; } } 2. What will be the results of the following code? final int ARRAY_SIZE = 5; double[] x = new double[ARRAY_SIZE]; for(int i = 1; i <= ARRAY_SIZE; i++) { x[i] = 10.0; } 3.What is the value of numbers [3] after the following line...
Write VHDL code for the following: Use HEX-to-seven segment display converters to display the inputs and...
Write VHDL code for the following: Use HEX-to-seven segment display converters to display the inputs and results for a 4-bit adder. The inputs are unsigned 4-bit binary numbers. The outcome is a 4-bit binary adder with LED display. First you need to create a symbol for the HEX-to-seven segment display converter. Then implement a 4-bit adder using VHDL. Finally, connect three HEX-to-seven segment display converters to display input X, input Y, and sum S.
Calculate the Residual Income (RI) for each of the following segments. Segment 1                           Segment 2&nbs
Calculate the Residual Income (RI) for each of the following segments. Segment 1                           Segment 2                       Segment 3     Income                 $ 180,000           $ 1,000,000             $ 500,000     Investment            2,000,000         5,000,000               2,000,000 Minimum Income (10%) 200,000         500,000                200,000
Write assembly code for the following machine code. Assume that the segment is placed starting at...
Write assembly code for the following machine code. Assume that the segment is placed starting at location 80000. Create labels for jump and branch instructions. Indicate the actual memory addresses represented by such labels. 0010 1010 0000 1000 0000 0000 0000 1010 0001 0001 0000 0000 0000 0000 0000 0010 0000 0010 0001 0001 1000 0000 0010 0000 0000 1000 0000 0000 0100 1110 0010 0101 0000 0010 0001 0010 1000 0000 0010 0000
a. Write machine code for the following assembly code. Assume that the segment is placed starting...
a. Write machine code for the following assembly code. Assume that the segment is placed starting at location 80000. Use decimal numbers to represent each instruction. loop:         beq $s3, $s1, endwhile                  add $t0, $s3, $s4                  lw $t1, 0($t0)                  add $s0, $s0, $t1                  addi $s3, $s3, 4                  j loop endwhile: b. Write assembly code for the following machine code. Assume that the segment is placed starting at location 80000. Create labels for jump and branch instructions. Indicate the actual...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT