Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     double x;
  6.     cin >> x;
  7.     double mid, temp, check = 0;
  8.     double low = 0, high = x;
  9.     mid = (low + high) / 2;
  10.     while((mid * mid) != x){
  11.         if(check != 0) mid = (low + high) / 2;
  12.         check = 1;
  13.         temp = mid * mid;
  14.  
  15.         if(temp > x){
  16.             high = mid;
  17.  
  18.         }
  19.         else if(temp < x){
  20.             low = mid;
  21.         }
  22.     }
  23.     cout << mid << endl;
  24.  
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement