#include int find_sqrt(int a, int b, int x) // want square root of x, given // that it will be between a and b { const int mid = (a+b)/2; cout << "my guess is " << mid << "\n"; if (b <= a) // this lets it give a good answer when an exact return mid; // does not exist if (mid*mid == x) { cout << "I won\n"; return mid; } else if (mid*mid > x) return find_sqrt(a, mid-1, x); else return find_sqrt(mid+1, b, x); } int my_sqrt(int N) { return find_sqrt(0, N+1, N); } void main() { cout << "sqrt(6400) is " << my_sqrt(6400) << "\n"; cout << "sqrt(6300) is around " << my_sqrt(6300) << "\n"; }