Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. #include <conio.h>
  5. #include <math.h>
  6. #include "stdafx.h"
  7. using namespace std;
  8. double f(double  x)
  9. {
  10.     return cos(x);
  11. }
  12. int _tmain(int argc, _TCHAR* argv[])
  13. {
  14.     setlocale(LC_ALL, "uk");
  15.  
  16.     int exit = 0;
  17.     double a, b, c = 0, e;
  18.  
  19.    
  20.     do
  21.     {
  22.         cout << " Введіть проміжок\n";
  23.         cout << "Start a=";
  24.         cin >> a;
  25.         cout << "End b=";
  26.         cin >> b;
  27.         cout << "Введіть похибку e=";
  28.         cin >> e;
  29.        
  30.         if (a > b)
  31.         {
  32.             c = a;
  33.             a = b;
  34.             b = c;
  35.         }
  36.         if (f(a)*f(b) > 0)  
  37.             cout << "Корені рівняння відсутні";                          
  38.         else
  39.         {
  40.             while ((fabs(b - a)) > e )
  41.             {
  42.                 if (f(a)*f(c) < 0)
  43.                     b = c;
  44.                 else
  45.                     a = c;
  46.                 c = (a + b) / 2;
  47.             }
  48.             cout << "\n" << "c=" << c << endl;
  49.         }
  50.         cout << "\n Вихід?";
  51.         cin >> exit;
  52.     }
  53.     while (exit != 1); // поки користувач не введе exit = 1
  54.     system("pause");
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement