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      } }
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...
Enter two valid BCD numbers. Show the result in seven segment display and LED How to...
Enter two valid BCD numbers. Show the result in seven segment display and LED How to do this using the components dip switch, Two BCD adders 74ls83, And gates, OR gates, 74 ls47 decoder, 7 segment display and LED
Consider the following code segment:    count = 1    while count <= 10:       print(count,...
Consider the following code segment:    count = 1    while count <= 10:       print(count, end=" ") Which of the following describes the error in this code? The loop control variable is not properly initialized. The comparison points the wrong way. The loop is infinite. The loop is off by 1. Does this code contain an error? If so, what line is the error on? 0: ans = input("Yes/No? ") 1: if ans == "Yes": 2: print("Confirmed!") 3: else...
Fill in the blanks of the following segment of code, so that the output would be 1 3 4.
Fill in the blanks of the following segment of code, so that the output would be 1 3 4.int count = 0;do{++ count;if (count == 2)Blank;cout << count << " ";} while (count <= Blank);cout << endl;
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT