#include <stdio.h>
#include <math.h>

void main()  {

	double start, end;  /*The starting and ending points for integration*/
	double n;           /*The number of partitions for trapezoid rule*/

	double delta_x;
	double C;	    /*The constant value (2) used in front of x[1] to x[n-1] terms*/

	int i;              /*Value for the for loop*/
	int x;

	double func = 0;        /*The function to be integrated*/

	printf("Enter the lower limit of integration: ");
	fflush(stdin); scanf("%lf", &start);

	printf("Enter the upper limit of integration: ");
	fflush(stdin); scanf("%lf", &end);

	printf("Enter the number of partitions: ");
	fflush(stdin); scanf("%lf", &n);

	delta_x = (end - start) / n;

	/*The following for loop will perform the integration*/

	for(i = start;  i <= n; i++)  {

		x = start + i*delta_x;

		if(i == start || i == end) C = 1;
		else C = 2;
		func += C*(5*x + sin(9*x - 5)/x);
	}/*end for() */

	func = delta_x / 2 * func;

	printf("The value of the approximation is: %lf", func);

}/*end main()*/

		
		
		
	
	
