剑指offer---数值的整数次方

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);
        }

    }
};

 

posted @ 2017-08-06 17:06  双马尾是老公的方向盘  阅读(152)  评论(0编辑  收藏  举报