Saturday, 8 March 2014

TRAPEZOIDAL PROGRAM

/*CSEMATTER.BLOGSPOT.IN

PROGRAM-PROGRAM FOR TRAPEZOIDAL RULE*/

#include<stdio.h>
#include<conio.h>
#define f(x) 1/(1+x*x)
void main()
{
int i,n;
float s1=0.0,s2=0.0,h,sum;
float x[10];
float y[10];
clrscr();
printf("enter the values of n");
scanf("%d",&n);
printf("enter the values of x");
for(i=0;i<n;i++)
scanf("%f",&x[i]);
h=x[1]-x[0];
for(i=0;i<n;i++)
y[i]=f(x[i]);
printf("for trapezoidal");
s1=(y[0]+y[n-1]);
for(i=1;i<n-1;i++)
{
s2=s2+(2*y[i]);
}
sum=((s1+s2)*h)/2;
printf("%f/n",sum);
getch();
}
/* OUTPUT
enter the values of n 7
0 1 2 3 4 5 6
for trapezoidal
1.410799*/

No comments:

Post a Comment