Limited access

Upgrade to access all content for this subject

Jim wrote a procedure that calculates a base raised to a certain exponent. The procedure has two parameters: base and exponent. This procedure can be seen below:

    PROCEDURE exp (base, exponent) 
        x ←1;
        REPEAT exponent TIMES
            x ← x * base
        RETURN (x) 

Which of the following changes could be made to the above code without altering the outcome?


Change “x ← x * base” to “x * base ← x”


Change “x ← x * base” to “x ← base * x”


Change “REPEAT exponent TIMES” to “REPEAT UNTIL (exponent = 1)”


None of these would work without altering the outcome.

Select an assignment template