GeeksForGeeks Power(x,n)
2016-02-08 07:16
288 查看
This is a example to use the divide and conquer
Power(x,n)这里用一个int tem 记录Power(x, n/2),然后将两者相乘得到的结果就可以,所以如果计算Power(x,n)就是计算Power(x,n/2)
然后将结果返回
int power(int x, unsigned int y)
{
int temp;
if( y == 0)
return 1;
temp = power(x, y/2);
if (y%2 == 0)
return temp*temp;
else
return x*temp*temp;
}
Write a program to calculate pow(x,n)
Power(x,n)这里用一个int tem 记录Power(x, n/2),然后将两者相乘得到的结果就可以,所以如果计算Power(x,n)就是计算Power(x,n/2)然后将结果返回
int power(int x, unsigned int y)
{
int temp;
if( y == 0)
return 1;
temp = power(x, y/2);
if (y%2 == 0)
return temp*temp;
else
return x*temp*temp;
}
相关文章推荐
- jquery操作select(取值,设置选中)
- js一点代码备用
- 【Leetcode】Maximum Depth of Binary Tree
- 正则实现文本框只能输入16个数字,每4位数字后添加一个空格
- 造轮子:js限制文本框只能输入数字方法
- 入学一月谈
- 入学一月谈
- 05-mac下SecureCRT安装
- php面向对象之——类的定义和属性方法的调用
- Kinect For Windows V2开发日志五:使用OpenCV显示彩色图像及红外图像
- Atitit.跨语言数据库db api兼容性 jdbc odbc ado oledb 增强方案
- Atitit.跨语言数据库db api兼容性 jdbc odbc ado oledb 增强方案
- Atitit.跨语言数据库db api兼容性 jdbc odbc ado oledb 增强方案
- [Redux] Passing the Store Down with <Provider> from React Redux
- 算法导论例程——基数排序
- 创建mysql数据表基础操作
- mysql基础指令和数据库基本操作
- html实战中遇到的问题
- HTML学习笔记(一)———基本结构
- Splay 模板