Write a definition of function powerOf2(n) so that powerOf2(n) = 2n. Assume that n is a nonnegative integer.

For example, powerOf2(1) = 2 and powerOf2(4) = 16.

For this problem, you are not allowed to use the ^ operator to compute powers. Instead, employ the idea of recursion. Notice the following two facts.

  1. 20 = 1
  2. 2n = 2(2n-1) (as long as n > 0).
Test your definition by pushing the Compute button. After it works, submit it by pushing the Submit button.

 

  [Language: Cinnameg  Kind: function definition]