#include<stdio.h>
#include<conio.h>
float f(float x){
float r;
r=2*x+1;
return r;
}
void main(){
float output;
float a,b;
float h,s;
int i,j;
int n;
clrscr();
printf("===========================================\n");
printf(" TRAPEZOIDAL RULE\n");
printf("===========================================\n");
printf("Enter the integral limit:-\n");
printf("-------------------------------------------\n");
printf("Lower limit value a: \n");
scanf("%f",&a);
printf("Upper limit value b: \n");
scanf("%f",&b);
printf("-------------------------------------------\n");
printf("Enter number of total intervals: \n");
scanf("%d",&n);
h=0.0;
h=(b-a)/n;
printf("____________________________________________\n");
printf("Resultant value of h is %.2f \n",h);
s=0.0;
s=f(a)+f(b);
printf("Resultant value of f(a) + f(b) is %.2f \n",s);
for (i=1;i<=n-1;i++)
{
s=s+2*f(a+i*h);
}
printf("Resultant value of whole summation of f(-) is %.2f\n",s);
output=1;
output=(h/2)*s;
printf("Output value of the integral is %.2f \n",output);
printf("____________________________________________\n");
printf(" GOOD LUCK\n");
getch();
}
#include<conio.h>
float f(float x){
float r;
r=2*x+1;
return r;
}
void main(){
float output;
float a,b;
float h,s;
int i,j;
int n;
clrscr();
printf("===========================================\n");
printf(" TRAPEZOIDAL RULE\n");
printf("===========================================\n");
printf("Enter the integral limit:-\n");
printf("-------------------------------------------\n");
printf("Lower limit value a: \n");
scanf("%f",&a);
printf("Upper limit value b: \n");
scanf("%f",&b);
printf("-------------------------------------------\n");
printf("Enter number of total intervals: \n");
scanf("%d",&n);
h=0.0;
h=(b-a)/n;
printf("____________________________________________\n");
printf("Resultant value of h is %.2f \n",h);
s=0.0;
s=f(a)+f(b);
printf("Resultant value of f(a) + f(b) is %.2f \n",s);
for (i=1;i<=n-1;i++)
{
s=s+2*f(a+i*h);
}
printf("Resultant value of whole summation of f(-) is %.2f\n",s);
output=1;
output=(h/2)*s;
printf("Output value of the integral is %.2f \n",output);
printf("____________________________________________\n");
printf(" GOOD LUCK\n");
getch();
}