You are on page 1of 2

/*PROGRAM FOR SIMPSON'S 1/3 RULE*/

#include<stdio.h>

#include<math.h>

#include<conio.h>

#include<stdlib.h>

float calc(float);

void main()

float x0,xn,h,y;

int i,sn;

clrscr();

printf("\nEnter the value of x0,xn,no. of sub intervals:\n");

scanf("%f %f %d",&x0,&xn,&sn);

h=(xn-x0)/sn;

y=calc(x0)+calc(xn);

for(i=1;i<sn;i++)

if (i%2==0)

y+=2*calc(x0+i*h);

y+=4*calc(x0+i*h);

y=(h/3)*y;

printf("\nValue of integer is %f",y);

getch();

float calc(float x)

return 1/(1+x*x);

You might also like