python怎么实现幂函数
python怎样实现幂函数
在python中利用递归实现一个幂函数,具体方法以下:
double PowerWithExponentUnsigned(double base, unsigned int exponentUnsigned)
{
// 最小子问题
if(exponentUnsigned == 0)
return 1;
double result = PowerWithExponentUnsigned(base,exponentUnsigned / 2);
result = result * result;
if(exponentUnsigned % 2 == 1)
{
result *= base;
}
return result;
}
文章来源:丸子建站
文章标题:python怎么实现幂函数
https://www.wanzijz.com/view/4441.html