
#include<iostream>
#include<cstdlib>
#include<cmath>

double integral( double (*f)(double), double a, double b, int n )
{
	double h= (b-a)/n;
	double sum= 0.0;
	for (int k=0; k<n; ++k)
		sum+= f(a+k*h);
	return sum*h;
}

int main(int argc, char *argv[])
{
	std::cout << integral(sin,0.0, M_PI,128) << std::endl;	
	std::cout << integral(cos, -M_PI/2.0, M_PI/2.0,128) << std::endl;	
	return EXIT_SUCCESS;
}

