Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. double f1(double x);
  5. double f2(double x);
  6. double rectangle(double a, double b, int kol, double (*f)(double x));
  7.  
  8. using namespace std;
  9. int main(){
  10. cout << "1 = " << rectangle(0,M_PI,100,f1) << endl;
  11. cout << "2 = " << rectangle(0,1,200,f2) << endl;
  12. return 0;
  13. }
  14.  
  15. double f1(double x){
  16. return (x*sin(x))/(1+(pow(cos(x),2)));
  17. }
  18. double f2(double x){
  19. return 1/(4-pow(x,2));
  20. }
  21. double rectangle(double a, double b, int kol, double (*f)(double x)){
  22. double x=a, h=(b-a)/kol,s=0;
  23. for (int i=1; i<kol; i++) {
  24. s+=f(x+(h/2));
  25. x+=h;
  26. }
  27. return s*h;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement