Code trace

The example below show tracing through a program one line at a time. During the
tracing process it is important to:

- keep track carefully of the values of variables

- keep track of the current line that is being executed

Consider the procedure mystery given below. What is returned (computed) after
the call mystery(2, 8)?


int mystery(int a, int b)
{
    int c = a;
    int d = b*c;
    int t = 0;
        
    while (c < d)
    {
        t = t + c;
        if (c >= b)
        {
            c = c + 1;
        }
        else
        {
            c = c + 2;
        }
        d = d - 1;
    }
        
    return t;
}
Click here to see the answer.