劍指offer---數值的整數次方
阿新 • • 發佈:2017-08-06
color for -- exp == ret cnblogs 整數 one
class Solution { public: double Power(double base, int exponent) { if (exponent > 0) { double sqr = 1; int i = 0; for (int i = 0; i < exponent; ++i) { sqr = sqr*base; } return sqr; }else if (exponent == 0) return 1; else { int zhengshu = abs(exponent); double sqr = 1; int i = 0; for (int i = 0; i < zhengshu; ++i) { sqr = sqr*base; } return (1/sqr); } } };
劍指offer---數值的整數次方