Showing posts with label 1/3 RULE. Show all posts
Showing posts with label 1/3 RULE. Show all posts

Tuesday, August 2, 2016

ALGORITHM OF SIMPSON’S 1/3 RULE


ALGORITHM OF SIMPSON’S 1/3 RULE

1-Enter value of upper limit & lower limit
2-Enter value of sub-interval(n)
3-h=(b-a)/n
4-s=y(a)+y(b)
5-For (j=1 to n-1) dø
   if( j%2==0)
  {
   s= s+2*y(a+j*h)
  else
  s=s+4*y(a+j*h)
  }
6-Result = (h/3)*s
7-Print  “result”
8- exit( )

PROGRAM FOR SIMPSON 1/3 RULE

/*PROGRAM FOR SIMPSON 1/3 RULE*/


#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
float x0,xf,y,h;
float f(float);
clrscr();
printf("\n\nEnter the values of x0 & xf::");
scanf("%f%f",&x0,&xf);
printf("\n\nEnter the values of n::");
scanf("%d",&n);
h=(xf-x0)/n;
y=f(x0)+f(xf);
for(i=1;i<=n-1;i++)
{
y=y+2*f(x0+i*h);
}
y=y*h/2;
printf("\n\nThe result is::%f",y);
getch();
}
float f(float x)
{
return(1/(1+x*x));
}


/*************OUTPUT******************


 Enter the values of x0 & xf::0 6  
Enter the values of n::6
 The result is::1.410799 */