#include <iostream>
#include <cmath>
double PowerWithUnsignedExponent(double base, unsigned int exponent)
{
if (exponent == 0)
return 1;
if (exponent == 1)
return base;
double result = PowerWithUnsignedExponent(base, exponent >> 1);
result *= result;
if ((exponent & 0x1) == 1)
result *= base;
return result;
}
int main()
{
printf("3.0^4=%.2f\n",PowerWithUnsignedExponent(3.0,4));
return 0;
}
剑指offer--面试题16:数值的整数次方
最新推荐文章于 2021-04-28 19:53:53 发布