?

AP® Computer Science Principles

Free Version

Upgrade subject to access all content

Easy

Exponent Procedure

APCSP-EGKURL

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?

A

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

B

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

C

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

D

None of these would work without altering the outcome.