2013年11月10日

Sqrt(x)

摘要: Implementint sqrt(int x).Compute and return the square root ofx.思路:使用二分。为了减少搜索范围,将上界定位最大的整数的开方,也避免了整数越界的情况。另外在第9行分别先除2再相加,也是避免越界。代码: 1 int border(int a){ 2 if(a x){15 return sqrt(left, middle, x);16 }17 else18 return middle;19 }20 int sqrt... 阅读全文

posted @ 2013-11-10 00:51 waruzhi 阅读(287) 评论(0) 推荐(0) 编辑

导航