EXPLORING CYBERSPACE…

Trapezoidal Rule

June 10, 2009 · Leave a Comment

#include<conio.h>
#include<stdio.h>
#include<dos.h>

float func(float x)
{
return(x/(5+2*x));
}

void main()
{
clrscr();
float result,a,b,h,sum=0;
int i,j,n;
printf("Enter the lower limit");
scanf("%f",&a);
printf("Enter the upper limit");
scanf("%f",&b);
printf("Enter the no. of sub-intervals");
scanf("%d",&n);
h=(b-a)/n;
sum=func(a)+func(b);
for(i=1;i<=n;i++)
{
sum+=(2*func(a+(i)*h));
}
result=(sum*h)/2;
printf("The value of integral is %f",result);
delay(4000);
}

Categories: Numerical Techniques · Programming in C

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment