Advertisement
istomina_sofia

нахождение площади методом треугольников

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