题解 | #数值的整数次方#
数值的整数次方
http://www.nowcoder.com/practice/1a834e5e3e1a4b7ba251417554e07c00
public:
double Power(double base, int exponent) {
double result=1;
int i;
//暴力法
if(exponent>0){
for(i=1;i<=exponent;i+=1){
result*=base;
}
}
else{
exponent=-exponent;
for(i=1;i<=exponent;i+=1){
result*=1/(base);
}
}
return result;
}
};