读书人

兑现指数函数Power

发布时间: 2012-10-17 10:25:47 作者: rapoo

实现指数函数Power


该题目不解释了,看代码,使用二分的思想,

//int Power(int base, int exponent){int result = 1;while (exponent){if (exponent & 1){result *= base;}base *= base;exponent >>= 1;}return result;}


Notice:

上述代码没考虑溢出的情况


读书人网 >编程

热点推荐