index
| submit
| rank
| book

## power – Exponentiation

Write a program that
performs integer exponentiation of a base *b* to the power of *n*.

*bⁿ* = 1 × *b* × *b* × … × *b* where *b* is repeated *n* times

for example

2⁵ = 1 × 2 × 2 × 2 × 2 × 2 = 32

### Input and output

Input will contain several lines each with two integers *b* and *n* where

*-1000 ≤ b ≤ 1000*

*0 ≤ n ≤ 30*

For each line of input,
output should contain a corresponding line
with a single integer indicating the value of *bⁿ*.

Input will be given so that

*-1 000 000 000 < bⁿ < 1 000 000 000*

#### The `power`

function

Your program should contain a `power`

function
that takes two integers and returns an integer.
The first integer argument should be the base and the second the exponent.
Please refer to the information for your chosen language:

- C prototype:
`int power(int b, int n);`

- Haskell type:
`power :: Int -> Int -> Int`

- Python definition:
`def power(b, n):`

- C++ prototype:
`int power(int b, int n);`

- Lua definition:
`function power (b, e)`

You should perform the exponentiation as a series of multiplications.
For this exercise,
you should restrain from using your programming languages'
built-in exponentiation functions.

### Scoring

- 1/6: works for the above example albeit in an incorrect format
- 2/6: works for the above example in the correct format
- 3/6: works for other examples
- 4/6: has good performance
- 5/6: works for edge cases
- 6/6: implements the
`power`

function

try first: factorial power1

try next: fibonacci

index
| submit
| rank
| book

Copyright © 2020-2021 Rudy Matela

All rights reserved