Advertisement
istomina_sofia

нахождение площади методом трапеций

Jun 25th, 2021
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. int main()
  5. {
  6.     setlocale(LC_CTYPE, "RUS");
  7.     float a = -2, b = 7;
  8.     float s = 0, S = 0;
  9.     float x = a, y;
  10.     int n;
  11.     cout << "Введите количество трапеций ";
  12.     cin >> n;
  13.     float h = (b - a) / n;// h - высота трапеции
  14.     for (int i = 1; i <= n - 1; i++)
  15.     {
  16.         x = a + i * h;
  17.         y = 5 * x - pow(x, 2) + 14;
  18.         S += h * (y + s) / 2;
  19.         s = y;
  20.     }
  21.     cout << " S = " << S << endl;
  22.  
  23.     return  0;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement