EXPLORING CYBERSPACE…

Integretion using Simpson’s 3/8 rule

June 10, 2009 · Leave a Comment

#include<conio.h>
#include<stdio.h>
#include<dos.h>
float func(float x)
{
 return(1/(1+x*x));
}

void main()
{
 clrscr();
 float result,a,b,h,sum=0;
 int i,j,n;
 printf("Enter the lower limit");
 scanf("%f",&a);
 printf("Enter the upper limit");
 scanf("%f",&b);
 printf("Enter the no. of sub-intervals");
 scanf("%d",&n);
 h=(b-a)/n;
 sum=func(a)+3*(func(a+h))+func(b);
 for(i=2;i<n;i++)
 {
 if(i%3==0)
 sum+=2*func(a+i*h);
 else
 sum+=3*func(a+i*h);
 }
 result=(sum*h*3)/8;
 printf("The value of integral is %f",result);
 delay(4000);
}

Categories: Numerical Techniques · Programming in C

0 responses so far ↓

  • There are no comments yet...Kick things off by filling out the form below.

Leave a Comment