Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- const double e = 0.000001;
- double function(double x)
- {
- return 2 + 2 * x; // исходное уравнение f(x)=0;
- }
- double d(double a, double b, double c)
- {
- while (b - a > e)
- {
- c = (a + b) / 2;
- if (function(b) * function(c) < 0)
- a = c;
- else
- b = c;
- }
- return ((a + b) / 2);
- }
- int main()
- {
- double a, b, c;
- cin >> a >> b;
- cout << d(a, b, e);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment