You are on page 1of 2

#include<stdio.

h>
#include<conio.h>
#include<math.h>
void main()
{
int c=0;
int i=0,j=0,n=0;
float h=0,x[10],y[10],s1=0, i1=0, i2=0, m0=0, m1=0,m2=0, h3=0, sum=0;
clrscr();
printf("enter the value of n:\n");
scanf("%d",&n);
printf("enter the values of x & y:\n");
for(i=0;i<n;i++)
{
printf("\nx[%d]:",i);
scanf("%f", &x[i]);
printf("\ny[%d]:",i);
scanf("%f", &y[i]);
}
h=x[2]-x[1];
printf("\nh=%f",h);
for(i=0;i<n;i++)
{
printf("a[%d]= %f", i,y[i]);
printf("\n");
}
while(1)
{
printf("\nenter 1 for simpson 1/3");
printf("\nenter 2 for simpson 3/8");
printf("\nenter 3 for exit");
printf("\nenter ur choice\n");
scanf("%d", &c);
if(c==1)
{
m0=y[0]+y[n-1];
printf("\nm0=%f", m0);
i=1;
while(i<n-1)
{
if(i%2==1)
{
i1=i1+y[i];
i=i+2;
}
}
printf("\ni1=%f", i1);
m1=i1*4;
printf("\nm1= %f", m1);
j=2;
while(j<n-1)
{
if(j%2==0)
{
i2=i2+(y[j]);
j=j+2;
}

}
printf("\ni2=%f", i2);
m2=i2*2;
printf("\nm2= %f", m2);
h3=h/3;
printf("\nh3=%f", h3);
sum=m1+m2+m0;
printf("\nsum= %f", sum);
s1=h3*sum;
printf("answer is: s1= %f", s1);
}

if(c==2)
{
float a=0,b=0;
for(i=3;i<n;)
{
a=a+(y[i]);
i=i+3;
}
for(j=1;j<n;j++)
{
if(j%3==0)
{
continue;
}
else
b=b+(y[j]);
}
s1=(3*h*((y[0]+(2*a)+(3*b)+y[n]))/8);
printf("\nthe value is %f",s1);
}
if(c==3)
exit();
}
getch();
}

You might also like