Tweet
// Trapezoidal Rule
#include<stdio.h>
float f(float x)
{
return (1/(1+x*x));
}
main()
{
int i,n;
float a,b,h,s=0,t;
printf("\nProgram to implement trapezoidal 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;
for(i=1;i<n;i++)
s=s+f(a+i*h);
t=(h/2)*(f(a)+2*s+f(b));
printf("\nThe result is : %6.4f\n",t);
}
Trapezoidal Rule in C
Posted by
LAHAUL SETH
~
Trapezoidal Rule in C
2011-12-23T08:47:00+05:30
LAHAUL SETH
Numerical Methods
|
Programming in C
|
Comments
Trapezoidal Rule in C
2011-12-23T08:47:00+05:30
LAHAUL SETH
Numerical Methods
|
Programming in C
|