offer12 数值的整数次方
数值的整数次方
http://www.nowcoder.com/questionTerminal/1a834e5e3e1a4b7ba251417554e07c00
public class Solution {
public double Power(double base, int exponent) {
double value=1.0;
if(exponent==0){
return 1;
}
if (base == 0){
return 0;
}
if(exponent>0){
double mul=1.0;
for(int i=1;i<=exponent;i++){
mul=base;
}
value=mul;
}
if(exponent<0){
int m=-exponent;
double mul=1.0;
double base1=1.0/base;
for(int i=1;i<=m;i++){
mul=base1;
}
value=mul;
}
return value;
}
}