Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- double f1(double x);
- double f2(double x);
- double rectangle(double a, double b, int kol, double (*f)(double x));
- using namespace std;
- int main(){
- cout << "1 = " << rectangle(0,M_PI,100,f1) << endl;
- cout << "2 = " << rectangle(0,1,200,f2) << endl;
- return 0;
- }
- double f1(double x){
- return (x*sin(x))/(1+(pow(cos(x),2)));
- }
- double f2(double x){
- return 1/(4-pow(x,2));
- }
- double rectangle(double a, double b, int kol, double (*f)(double x)){
- double x=a, h=(b-a)/kol,s=0;
- for (int i=1; i<kol; i++) {
- s+=f(x+(h/2));
- x+=h;
- }
- return s*h;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement