/*CSEMATTER.BOGSPOT.IN
PROGRAM-TO IMPLEMENT SIMPSON'S 3/8 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]);
s1=(y[0]+y[n-1]);
printf("for simpson's 3/8 rule");
for(i=1;i<n-1;i++)
{
if(i%3!=0)
s2=s2+y[i];
else
s3=s3+y[i];
}
sum=(((s1+(3*s2)+(2*s3))*3*h))/8;
printf("%f/n",sum);
getch();
}
/* OUTPUT
enter the values of n 7
0 1 2 3 4 5 6
for simpson's 3/8 rule
1.357081*/
PROGRAM-TO IMPLEMENT SIMPSON'S 3/8 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]);
s1=(y[0]+y[n-1]);
printf("for simpson's 3/8 rule");
for(i=1;i<n-1;i++)
{
if(i%3!=0)
s2=s2+y[i];
else
s3=s3+y[i];
}
sum=(((s1+(3*s2)+(2*s3))*3*h))/8;
printf("%f/n",sum);
getch();
}
/* OUTPUT
enter the values of n 7
0 1 2 3 4 5 6
for simpson's 3/8 rule
1.357081*/
No comments:
Post a Comment