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