Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1.  
  2. // y = 3x^2 - 4x + 2
  3. // y = 20 - x
  4.  
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. float f1(float x)
  10. {
  11.     return 20 - x;
  12. }
  13.  
  14. float f2(float x)
  15. {
  16.     return 3 * x * x - 4 * x + 2;
  17. }
  18.  
  19. int main()
  20. {
  21.     setlocale(LC_ALL, "russian");
  22.     cout << "y = 3x^2 - 4x + 2\ny = 20 - x\n";
  23.     float a, b, n, h, s1 = 0, s2 = 0;
  24.     cout << "Введите пределы интегрирования от a до b:\na: ";
  25.     cin >> a;
  26.     cout << "b: ";
  27.     cin >> b;
  28.     cout << "Введите количество интервалов разбиения: ";
  29.     cin >> n;
  30.     h = (b - a) / n;
  31.     for (int i = 0; i <= n - 1; i++)
  32.     {
  33.         s1 += f1(a);
  34.         s2 += f2(a);
  35.         a += h;
  36.     }
  37.     cout << "Площадь: " << (s1 - s2) * h << endl;
  38.     system("Pause");
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement