Tuesday 20 September 2011

Trapezoidal Rule


/* This program finds area of the function by Trapezoidal Rule*/

#include<stdio.h>
#include<math.h>

float area(float a)
{
 float f;
 f=1/(sqrt(1+a*a));
 return (f);
 }

 void main()
 {
 int i,n;
 float a,b,h, sum1,sum2,sum;
 clrscr();
 printf(" Type the lower limit a and upper limit b\n");
 scanf("%f%f", &a,&b);
 printf(" Type the number of interval n\n");
 scanf("%d", &n);
 sum1=area(a);
 sum1+=area(b);
 sum2=0;
 h=(b-a)/n;
 for(i=1;i<n;i++)
 sum2+=area(a+i*h);
 sum=h*(sum1+2*sum2)/2;
 printf(" The required area = %8.4f\n", sum);
 getch();
 }