1. 程式人生 > >劍指offer---數值的整數次方

劍指offer---數值的整數次方

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---數值的整數次方