C programming to calculate value using composite trapezoidal rule
#include<stdio.h>}
#include<conio.h>
#include<math.h>
#define F(x) 2*x
int main()
{
int n,i;
float a,b,h,x,sum=0,integral;
printf("Enter the two limits:\n");
scanf("%f%f",&a,&b);
printf("Enter the difference n:\n");
scanf("%d",&n);
h=(b-a)/n;
for(i=1;i<n;i++)
{
x=a+i*h;
sum=sum+F(x);
}
integral=(h/2)*(F(a)+F(b)+2*sum);
printf("\nThe integral is: %f\n",integral);
return 0;
Post A Comment:
0 comments so far,add yours