You are on page 1of 1

Date:-

~: PROGRAM OF SIMPSONS 1/3 RULE: ~


#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i,n;
float a,b,h,p,sum;
float f(float x);
clrscr();
printf("\nEnter the value of a,b,n ");
scanf("\n %f %f %d",&a,&b,&n);
h=(b-a)/n;
sum=f(a)+f(b);
for(i=1;1<=n-1;i+=2)
{
p=a+(i*h);
sum=sum+4*f(p);
}
sum=sum*(h/3);
printf("\nThe result =%f ",sum);
getch();
}
float f(float x)
{
float m;
m=((1-x)/(1+x));
return(m);
}

INPUT & OUTPUT


Enter the value of a,b,n
0
1
10
The result =
0.387500

Pg.4

You might also like