Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <conio.h>
- #include <math.h>
- #include "stdafx.h"
- using namespace std;
- double f(double x)
- {
- return cos(x);
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- setlocale(LC_ALL, "uk");
- int exit = 0;
- double a, b, c = 0, e;
- do
- {
- cout << " Введіть проміжок\n";
- cout << "Start a=";
- cin >> a;
- cout << "End b=";
- cin >> b;
- cout << "Введіть похибку e=";
- cin >> e;
- if (a > b)
- {
- c = a;
- a = b;
- b = c;
- }
- if (f(a)*f(b) > 0)
- cout << "Корені рівняння відсутні";
- else
- {
- while ((fabs(b - a)) > e )
- {
- if (f(a)*f(c) < 0)
- b = c;
- else
- a = c;
- c = (a + b) / 2;
- }
- cout << "\n" << "c=" << c << endl;
- }
- cout << "\n Вихід?";
- cin >> exit;
- }
- while (exit != 1); // поки користувач не введе exit = 1
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement