Simvik

Raise to a power

Multiply repeatedly inside a loop. An easy embedded C problem (Decisions and loops), run and graded in the browser.

easy · Decisions and loops · loops

Return base raised to the power exp. exp is never negative, and anything to the power 0 is 1.

Starter code

int power(int base, int exp) {
  int result = 1;
  // Multiply result by base, exp times.
  return result;
}

Example tests

Two to the tenth

printf("%d\n", power(2, 10));

Expected output:

1024

Three cubed

printf("%d\n", power(3, 3));

Expected output:

27

Learn it first

  • Decisions and loops · Choosing with if and switch, repeating with while and for, and the loop that never ends.

More Decisions and loops problems