Tuesday, August 2, 2016

PROGRAM FOR TRAPEZOIDAL RULE

/*PROGRAM FOR TRAPEZOIDAL RULE*/


#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
float x0,xf,y,h;
float f(float);
clrscr();
printf("\n\nEnter the values of x0 & xf::");
scanf("%f%f",&x0,&xf);
printf("\n\nEnter the values of n::");
scanf("%d",&n);
h=(xf-x0)/n;
y=f(x0)+f(xf);
for(i=1;i<=n-1;i++)
{
y=y+2*f(x0+i*h);
}
y=y*h/2;
printf("\n\nThe result is::%f",y);
getch();
}
float f(float x)
{
return(1/(1+x*x));
}


/* ******************OUTPUT*****************


Enter the values of x0 & xf::0
1
Enter the values of n::6
The result is::0.784241*/

No comments:

Post a Comment