Linux 拨号vps windows公众号手机端

python怎么实现幂函数

lewis 6年前 (2019-03-31) 阅读数 8 #程序编程
文章标签 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;

}

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门