Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define EPS 1E-9
- double f(double x)
- {
- //монотонная функция на отрезке [a, b], например f(x) = x^3:
- return x*x*x;
- }
- double binarySearch(double C, double a, double b)
- {
- double low = a, high = b;
- while(abs(low-high) < EPS)
- {
- double mid = low + (high - low) / 2;
- if f(mid) < C
- low = mid;
- else
- high = mid;
- }
- return (low + high)/2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement