Answer
procedure pow ($x$ a real number, $n$ an integer)
if $n>0$ then return positivepow($x, n$)
else if $x$ is $0$ then return undefined
else return 1/positivepow($x, -n$).
procedure positivepow($x$ a real number, $n$ a positive integer)
if $x$ is $0$ then return $0$
else product:=1
for $i:=1$ to $n$
$\space\space\space$product:= product $\times x$
return product
Work Step by Step
The aim of this exercise is to derive an algorithm that, when given $x$ and $n$, can calculate $x^n$. Edge cases must be handled carefully such as the the case where $x=0$ to make sure the algorithm is robust.
First, as suggested in the question, we define a positivepow procedure which assumes that the power is positive and works accordingly. Notice that when $n=0$, our algorithm handles that case properly as well since it returns $1$ (because the loop never executes as the condition is false from the very beginning)
For the negative power, we extend the positivepow procedure making use of the relation $x^{-n}=\frac{1}{x^n}$.
For $x=0,$ the algorithm should return $1$ for $n>0$; undefined otherwise which what the above algorithm does.