In: Computer Science
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)
}
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