In: Computer Science
construct the trace table or trace table list for the
function call CR (111) where the definition of CR () is
bool CR ( int n )
{
bool w,x,y,z,r;
int c;
c= 3*n;
c + = 16;
c=c%5;
w=c==4;
Trace Table
n | c | w |
111 | - | - |
111 | 333 | - |
111 | 349 | - |
111 | 4 | - |
111 | 4 | 4 |
Explaination:
The value given to us is CR(111) that means the initial value of n is 111. The variables that we need to add in the Trace Table are n, c and w as these are the only variables that are used in this set of code.
In the first step we need to check the initial values of all the 3 variables and make an entry in the first row accordingly. the initial value of n is 111 and for c & w we don't have any value so we are simply putting "-".
In the 5th line of the code the value of c is changed to 333 as it says c=3*n i.e. c=3*111 which is 333 so the 2nd row in the trace table is filled as n 111 (as the value of n is not changed) , c 333 and we don't have any value for w yet so "-".
Now, in the 6th line of the code the value of c is changed to 349 as it says c+=16 i.e. c=333+16 which is 349 so the 3rd row of the trace table is filled as n 111 (no change) , c 349 and w "-".
In the 7th line of the code, the value of c is changed to 4 as it says c=c%5 i.e. c=349%5 which is 4 (% modulus operator gives the remainder of 2 numbers); so the 4th row is filled as n 111(no change) , c 4 and w "-".
In the last line of the code, we are assigning the value of c to w if the value of c is 4 which is true so the last row of the trace table is filled as n 111 (no change yet) , c 4 and w also 4.
I hope I made the solution clear enough to understand!!