Electrical and Computer Engineering
8
of 24
UAH
CPE 112
Revisiting the Power Function
•
float
power (
int
base,
int
exponent)
•
{
•
int
i =1;
•
float
result = 1.0;
•
•
while
(i <= abs(exponent))
•
{
•
result = result * base;
•
i++;
•
}
•
if
(exponent < 0)
•
result = 1.0/result;
•
return
result;
•
}
•