11.8. Homework 8 - A Recursive FunctionΒΆ
See also
For this assignment, we will write our own function similar to the math
library function pow(a, k)
, which computes
where
and
are both scalar values. For our function,
we will restrict the scalar
to the set of positive integer numbers.
The function prototype statement for our function might be:
double my_pow(double, unsigned int);
The basis for our recursive algorithm is the simple mathematical relationship
By splitting in half each time
is an even number,
the number of multiplications is greatly reduced.
Thus, our function should evaluate
to one of the following cases.
k == 0:
k == 1:
k is an even number:
k is an odd number: