温馨提示×

python怎么实现幂函数

九三
1021
2021-02-18 18:34:00
栏目: 编程语言
Python开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

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;

}

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:python如何计算幂函数

0