Advertisement
KrimsN

Untitled

Dec 16th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1.    double SqrtNumber(double num)
  2.     {
  3.              double lower_bound=0;
  4.              double upper_bound=num;
  5.              double temp=0;                    /* ek edited this line */
  6.  
  7.              int nCount = 50;
  8.  
  9.         while(nCount != 0)
  10.         {
  11.                temp=(lower_bound+upper_bound)/2;
  12.                if(temp*temp==num)
  13.                {
  14.                        return temp;
  15.                }
  16.                else if(temp*temp > num)
  17.  
  18.                {
  19.                        upper_bound = temp;
  20.                }
  21.                else
  22.                {
  23.                        lower_bound = temp;
  24.                }
  25.         nCount--;
  26.      }
  27.         return temp;
  28.      }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement