| 
 | 
back to boardWhats wrong with this code? Please help #include<iostream> using namespace std; float sqrt(long long2 n,int p) {     int start = 0;     int end = n;     float ans;     int mid;     while(start <= end)     {         mid = (start+end)/2;         if(mid*mid < n)             start = mid + 1;         else if(mid*mid > n)             end = mid - 1;         else         {             ans = mid;             break;         }     }     float increment = 0.1;     for(int i = 0; i < p;i++)     {         while(ans * ans <= n)         {             ans += increment;         }         ans -= increment;         increment /= 10;     }     return ans; } int main() {     long long int n;     while(cin >> n)     {         cout << sqrt(n,4) << endl;     } } Re: Whats wrong with this code? Please help 1) Please read task, especially "from the last one till the first" carefully. Look at the example. 2) Your sqrt function lies.  https://ideone.com/wcJVz0 |  
  | 
|