nvnnaidenov

Zad68

Oct 28th, 2021
643
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5.  
  6. double next1(double);
  7. double next2(double);
  8. double prod(double, double, double (*)(double), double (*)(double));
  9.  
  10. int main()
  11. {
  12.     cout << prod(1, 3, tan, next1) << endl;
  13.     cout << prod(1, 1.3, atan, next2) << endl;
  14.  
  15.     return 0;
  16. }
  17.  
  18. double prod(double a, double b, double (*f)(double), double (*next)(double))
  19. {
  20.     double s = 1.0;
  21.  
  22.     for(double i = a; i <= b + 1e-14; i = next(i))
  23.     {
  24.         s = s * f(i);
  25.     }
  26.  
  27.     return s;
  28. }
  29.  
  30. double next1(double x)
  31. {
  32.     return x + 0.5;
  33. }
  34.  
  35. double next2(double x)
  36. {
  37.     return x + 0.1;
  38. }
RAW Paste Data