Advertisement
ilyakanyshev

Untitled

Dec 24th, 2020
866
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. double integral(int, int, double, double (*f)(double));
  7. double fun(double);
  8.  
  9.  
  10. int main()
  11. {
  12.     int a, b;
  13.     double epsil = 0.001;
  14.     cout << "Please, enter a: ";
  15.     cin >> a;
  16.     cout << "Please, enter b: ";
  17.     cin >> b;
  18.     cout << "Integral = " << integral(a, b, epsil, fun) << endl;
  19.     return 0;
  20. }
  21.  
  22. double fun(double x)
  23. {
  24.     return x;
  25. }
  26. double integral(int a, int b, double epsil, double (*f)(double))
  27. {
  28.     double s = 0;
  29.     for (double x = a; x < b; x += epsil)
  30.         s += fun(x+epsil);
  31.     return fabs(s)*epsil;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement