for Loops

AP Computer Science A· difficulty 4/5

Compute a^b iteratively:

<code>int p = 1; for (int i = 0; i < b; i++) p *= a; </code></pre> For a=3, b=4, p is

  • A

    7

  • B

    12

  • C

    81

    check_circle
  • D

    27

Explanation

3⁴ = 81.

Want 10 more like this — adaptive to your weak spots?

Related questions