Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
668 B
1
Indexable
Never
#include <iostream>
#include <cmath>
using namespace std;


double f(double x) {
    return 3 * x * x + 2 * x ;
}

double pole(double a, double b, int n) {
    double x = (b-a)/(double)n; 
    double S = 0.0; 
    double srodek = a+(b-a)/(2.0*n); 
 
    for(int i=0;i<n;i++)
    {
        S+=f(srodek); 
        srodek+=x;  
    }
    return S*x;
}

int main() {
    double a = -10.0;  //przedzial lewy
    double b = 10.0;    //przedzial prawy
    int n = 10000;

    double area = pole(a, b, n);
    double area_positive_y = (area < 0) ? 0 : area;

    cout << "Pole figury wynosi: " << area_positive_y << std::endl;
    return 0;
}