#include #include #define f(x) ((x)*(x)*exp(x)) #define exact_value 2.0*(exp(2)-1.0) main() { int i; float n,a,b,h,x1,x2,x3,ans,gosa; printf("N="); scanf("%f",&n); printf("[a,b]="); scanf("%f %f",&a,&b); ans=0.0; h=(b-a)/n; for(i=0;i<=n-2;i+=2){ x1=a+i*h; x2=x1+h; x3=x1+2.0*h; ans=ans+h/3.0*(f(x1)+4.0*f(x2)+f(x3)); } gosa=fabs(exact_value-ans); printf("N= %f\n",n); printf(" [%f,%f]\n",a,b); printf(" %15.7e\n",ans); printf("exact %15.7e\n",exact_value); printf("error %15.7e\n",gosa); return(0); }