# Numerical Methods Integration of given function using Simpsons 38 rule in C

Numerical Methods: Integration of given function using Simpson’s 3/8 rule in C

Source Code:

```//integration of given function using Simpson's 3/8 rule
#include

float y(float x){
return 1/(1+x*x); //function of which integration is to be calculated
}

int main(){
float x0,xn,h,s;
int i,n,j,flag;
printf("Enter x0, xn, no. of subintervals: ");
scanf("%f%f%d",&x0,&xn,&n);

h = (xn-x0)/n;
s = y(x0)+y(xn);

for(i = 1; i<=n-1;i++){
for(j=1;j<=n-1;j++){
if(i==3*j){
flag = 1;
break;
}
else
flag = 0;
}
if(flag==0)
s += 3*y(x0+i*h);
else
s += 2*y(x0+i*h);
}
printf("Value of integral is %6.4f\n",(3*h/8)*s);
return 0;
}

Related PostsAugust 9, 2012 Numerical Methods Integration of given function using Simpsons 13 rule in CAugust 7, 2012 Numerical Methods Integration of given function using Trapezoidal rule in CAugust 4, 2012 Numerical Methods Determinant of nxn matrix using CAugust 6, 2012 Numerical Methods Parabolic curve fitting using CAugust 11, 2012 Numerical Methods Condition number and ill condition checking using CZemanta

```