Implementation of Trapezoidal Rule.
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<process.h>
float fun(float);
void main()
{
float result=1;
float a,b;
float h,sum;
int i,j;
int n;
clrscr();
printf("\n\n Enter the range-");
printf("\n\n Lower Limit a-");
scanf("%f",&a);
printf("\n\n Upper Limit b-");
scanf("%f",&b);
printf("\n\n Enter number of subintervals-");
scanf("%d",&n);
h=(b-a)/n;
sum=0;
sum=fun(a)+fun(b);
for(i=1;i<n;i++)
{
if(i%3==0)
{
sum+=2*fun(a+i*h);
}
result=sum*h/2;
printf("\n\n\n Value of the intergal is %6.4f\t",result);
printf("Press enter to Exit");
getch();
}
float fun(float x)
{
float temp;
temp=1/(1+(x*x));
return temp;
}
Oh my goodness! You're so right! I'll buy a glass of beer to that person from that forum who told me to visit your site.
ReplyDeleteVISIT HERE: Funeral Homes Website Design and Marketing Solutions.