Saturday, 8 March 2014

SIMPSON'S 1/3 RD PROGRAM

/*CSEMATTER.BLOGSPOT.IN
PROGRAM FOR SIMPSON'S 1/3 RD 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,s3=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 simpson's 1/3 rd rule");
s1=(y[0]+y[n-1]);
for(i=1;i<n-1;i++)
{
if(i%2!=0)
s2=s2+y[i];
else
s3=s3+y[i]; }
sum=((s1+(4*s2)+(2*s3))*h)/3;
printf("%f/n",sum);
getch();
}


/* OUTPUT
enter the values of n 7
0 1 2 3 4 5 6
for simpson's 1/3 rd rule
1.366174*/

No comments:

Post a Comment