Simpson’s 1/3rd program in c for non tabulates values

 Simpson’s 1/3rd program in c for non tabulates values

#include<stdio.h>
#include<conio.h>
#include<math.h>
#define f(x) (x*x*x*x)

void main()
{
int i,n;
float h,s,s2,s4,integral,a,b;
clrscr();
printf("enter a and b then n :");
scanf("%f%f%d",&a,&b,&n);
h=(b-a)/(n);
s=f(a)+f(b);
s2=0;
s4=0;
for(i=1;i<=(n-2);i=i+2)
{
s2 = s2+f(a+i*h);
s4 = s4+f(a+(i+1)*h);
}
integral=(h/3)*(s+2*s2+4*s4);
printf("integral is %f",integral);
getch();
}

Leave a Reply

Your email address will not be published. Required fields are marked *