Write a program that performs integer exponentiation of a base b to the power of n.
bⁿ = b × b × … × b where b is repeated n times
for example
2⁵ = 2 × 2 × 2 × 2 × 2 = 32
Input will contain two integers b and n where 0 < b, n ≤ 9
Output should contain a single integer indicating the value of bⁿ.
2 5
32
5 2
25
power
functionYour 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:
int power(int b, int n);
power :: Int -> Int -> Int
def power(b, n):
int power(int b, int n);
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.
power
functiontry first: factorial1
try next: fibonacci1
Copyright © 2020-2021 Rudy Matela
All rights reserved