Thursday, 2 November 2017

C Programme for Trapezoidal Rule

#include<stdio.h>
#include<conio.h>
#include<math.h>
float f(float x)
{ return (1/(1+pow(x,2)));
}
void main()
{int i,n;
 float a,b,h,I,sum=0.0;
 clrscr();
 printf("enter the values of lower and upper limits 'a' and 'b'");
 scanf("%f%f",&a,&b);
 printf("enter the no. of subinetrvals n");
 scanf("%d",&n);
 h=(b-a)/n;
 sum=f(a)+f(b);
 for(i=1;i<n;i++)
 {sum=sum+2*f(a+i*h);
 }
 I=(h/2)*sum;
 printf("the value is %f:",I);
 getch();
}

Input/Output:


No comments:

Post a Comment