#include <stdio.h>
#include<math.h>
#define f(x) 1/(4*x+5)
int main()
{
int n;
double a,b,h,x,sum=0,ans,r;
printf("Enter the No. of N: ");
scanf("%d",&n);
printf("Enter the value of a and b: ");
scanf("%lf %lf",&a,&b);
h = (b-a)/n;
sum = f(a)+f(b);
for (int i = 1; i < n; i++)
{
r=a+i*h;
printf("x values: %.4lf\n",r);
if(i%2==0){
sum=sum+2*f(r);
}
else{
sum=sum+4*f(r);
}
}
ans = sum*h/3;
printf("%.4lf",ans);
return 0;
}
Comments
Post a Comment