Tweet
// Weddle's Rule
#include<stdio.h>
float f(float x)
{
return (1/(1+x*x));
}
main()
{
int i,n;
float a,b,h,s=0,x,y[20],s1=0,s2=0,s3=0,s4=0,t;
printf("\nProgram to implement weddle rule : \n");
printf("\nEnter the lower limit : ");
scanf("%f",&a);
printf("\nEnter the upper limit : ");
scanf("%f",&b);
printf("\nEnter the no. of sub-intervals : ");
scanf("%d",&n);
h=(b-a)/n;
x=a;
for(i=0;i<=n;i++)
{
y[i]=f(x);
x=x+h;
}
for(i=0;i<=n-6;i+=6)
{
s1=s1+y[i+2]+y[i+4];
s2=s2+y[i+1]+y[i+5];
s3=s3+y[i+3];
}
for(i=0;i<=n-12;i+=6)
s4=s4+y[i+6];
s=(3*h/10)*(y[0]+y[n]+s1+5*s2+6*s3+2*s4);
printf("\nThe result is : %6.4f\n\n",s);
}
Weddle's Rule in C
Posted by
LAHAUL SETH
~
Weddle's Rule in C
2011-12-23T08:49:00+05:30
LAHAUL SETH
Numerical Methods
|
Programming in C
|
Comments
Weddle's Rule in C
2011-12-23T08:49:00+05:30
LAHAUL SETH
Numerical Methods
|
Programming in C
|