Advertisement
labyyysosaaat

Untitled

Oct 21st, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4. double f(double x) { return (-3 * x*x + 2 * x + 9); }
  5. double I(double a, double b, int n, double y) { return ((b - a) / (2 * n)*y); }
  6. int main() {
  7. int n; double a, b, y, dy, In;
  8. cin >> a >> b >> n;
  9. if (n > 1) {
  10. dy = (b - a) / n;
  11. y += f(a) + f(b);
  12. for (int i = 1; i < n; i++) { y += 2 * (f(a + dy * i)); }
  13. In = I(a, b, n, y);
  14. cout << In;
  15. }
  16. else { cout << "Wrong data"; }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement