Using the following flow chart, do the following: a) Create an output table that
ID: 3652092 • Letter: U
Question
Using the following flow chart, do the following:
a) Create an output table that considers all variables if x is given an initial value of 132.
b) Determine which type of loop is described in the loop and justify your answer.
c) Identify the control variable within the loop and justify your answer.
d) What happens when x is given an initial value of -15? Redraw the flow chart in a way that prevents this from occurring.
Create a code snippet that accomplishes the same tasks as the newly redrawn flow chart. Be sure to include all include statements, variable declarations, and initializations that are necessary for the code to run correctly
Explanation / Answer
if X=132 INITIALLY COUNT=0 ITERATION-1 -------------------------------------- Y=X%6 =132%6 =0 SO Y=0; X=X/3 =132/3 =44 SO X=44; COUNT=COUNT+1; COUNT=1; ITERATION-2 -------------------------------------- Y=X%6 =44%6 =2 SO Y=2; X=X/3 =44/3 =14 SO X=14; COUNT=COUNT+1; COUNT=2; ITERATION-3 -------------------------------------- Y=X%6 =14%6 =2 SO Y=2; X=X/3 =14/3 =4 SO X=4; COUNT=COUNT+1; COUNT=3; ITERATION-4 -------------------------------------- Y=X%6 =4%6 =4 SO Y=4; X=X/3 =4/3 =1 SO X=1; COUNT=COUNT+1; COUNT=4; SO NOW THE CONDITION IS TRUE: OUTPUT IS: X=1 Y=4 COUNT=4;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.