Advertisement
Guest User

Perebor_Yana

a guest
May 26th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. double func(double x)
  6. {
  7.     return (-x * x + 6 * x + 5);
  8. }
  9.  
  10. double e = 0.01;
  11. double c;
  12.  
  13. double perebor(double a, double b, int n)
  14. {
  15.     double x, xmax;
  16.     double y = func(a);
  17.     for (int i = 0; i <= n; i++) {
  18.         x = a + i * (b - a) / (n + 1);
  19.         cout << "x=" << x << endl;
  20.         cout << "f(" << x <<")=" << func(x)<<endl;
  21.         if (func(x) > y) {
  22.             y = func(x);
  23.             xmax = x;
  24.            
  25.         }
  26.            
  27.  
  28.     }
  29.     cout << "Point of maximum is = " << xmax << endl;
  30.     cout << "Extr is = " << y << endl;
  31.     return 0;
  32. }
  33.  
  34. int main()
  35. {
  36.     double a, b;
  37.     int n;
  38.     a = 0;
  39.     b = 5;
  40.     cout << "a = " << a << endl;
  41.     cout << "b = " << b << endl;
  42.     cout << "Enter n:";
  43.     cin >> n;
  44.     perebor(a, b,n);
  45.     cout << "\n";
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement