#include #include using namespace std; double f( double x ) { return( x*x + 2*x + 3 ); // Function f(x) } int main() { double a, b, h, sum, x; short i, n; n = 100; // Number of subintervals a = 0.0; // Lower bound b = 2.0; // Upper bound h = ( b - a ) / n; sum = ( f( a ) + f( b ) ) / 2; x = a; for( i = 1; i <= n-1; i++ ) { x += h; sum += f( x ); } cout << "Trapezoid rule result: " << h * sum << endl; return( 0 ); }