Search:

Submit Article

# TRAPEZOIDAL RULE

Posted By: Lu Fischer     Category: C Programming     Views: 77159

## Code for TRAPEZOIDAL RULE in C Programming

```#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float x[10],y[10],sum=0,h,temp;
int i,n,j,k=0;
float fact(int);
clrscr();
printf("\nhow many record you will be enter: ");
scanf("%d",&n);
for(i=0; i<n; i++)
{
printf("\n\nenter the value of x%d: ",i);
scanf("%f",&x[i]);
printf("\n\nenter the value of f(x%d): ",i);
scanf("%f",&y[i]);
}
h=x[1]-x[0];
n=n-1;
for(i=0;i<n;i++)
{
if(k==0)
{
sum = sum + y[i];
k=1;
}
else
sum = sum + 2 * y[i];
}
sum = sum + y[i];
sum = sum * (h/2);
printf("\n\n  I = %f  ",sum);
getch();
}

/*______________________________________         OUT PUT______________________________________how many record you will be enter: 6enter the value of x0: 7.47enter the value of f(x0): 1.93enter the value of x1: 7.48enter the value of f(x1): 1.95enter the value of x2: 7.49enter the value of f(x2): 1.98enter the value of x3: 7.50enter the value of f(x3): 2.01enter the value of x4: 7.51enter the value of f(x4): 2.03enter the value of x5: 7.52enter the value of f(x5): 2.06  I = 0.099652*/```
Share:

Didn't find what you were looking for? Find more on TRAPEZOIDAL RULE Or get search suggestion and latest updates.

 Lu Fischer author of TRAPEZOIDAL RULE is from Frankfurt, Germany. View All Articles

 Please enter your CommentComment should be atleast 30 Characters.Please put code inside [Code] your code [/Code]. No Comment Found, Be the First to post comment!