Code for TRAPEZOIDAL RULE in C Programming

C code to implement TRAPEZOIDAL RULE  .  Compiled  in  DEV C++

website_caption1

#include<stdio.h>
#include<conio.h>
#include<math.h>
float fn(float x)
{
sqrt(x);
return sqrt(x);
}
main()
{
int i,n;
float a,b,s=0,y=0,h;
printf("Enter the no of interval =");
scanf("%d",&n);
printf("Enter the lower limit=");
scanf("%f",&a);
printf("Enter the upper limit=");
scanf("%f",&b);
h=(b-a)/n;
for(i=1;i<=n-1;i++)
{
s=s+fn(a+i*h);
}
y=(fn(a)+fn(b)+2*s)*h/2;
printf("the value of y is=%f",y);
getch();
}

website_caption1

You might be also interested in :

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s