码迷,mamicode.com
首页 > 其他好文 > 详细

实现sqrt()函数

时间:2020-05-09 23:06:14      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:方法   alt   return   技术   bsp   ret   com   code   ==   

方法一:

 

技术图片

 

 

  int mySqrt(int x) {

        if(x == 0)
         {
           return 0;
         }        
         int ans = exp(0.5*log(x));
         int k = ans+1;
         //int r = k*k;
         if((long long) k*k <=x)
         {
              return k;
         }
         else
         {
              return ans;
         }
    }

  

实现sqrt()函数

标签:方法   alt   return   技术   bsp   ret   com   code   ==   

原文地址:https://www.cnblogs.com/132818Creator/p/12860502.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!