[ New messages · Members · Forum rules · Search · RSS ]
  • Page 1 of 1
  • 1
Forum » Codeing » C ++ Examples of maths » Trapezoidal Rule (Trapezoidal Rule)
Trapezoidal Rule
pradeepDate: Monday, 16 January 12, 11:12 AM | Message # 1
pk
Group: Administrators
Messages: 82
Status: Offline
/* Trapezoidal Rule*/
#include
#include
#include
void main ()
{
float f (float x);
float x0, xn, h, sum, result;
int i, n;
clrscr();
printf("Enter the Lower Limits of Integral :");
scanf("%f",&x0);
printf("Enter the Upper Limits of Integral :");
scanf("%f",&xn);
printf("\n Enter the segment width :");
scanf("%f" ,&h);
n = (int)((xn - x0)/h);
sum = f(x0)+f(xn)/2;
for(i=1; i {
sum = sum+f(x0 +i*h );
}
result = sum*h;
printf("\n\n Value of integral using trapezoidal rule is =%f\n\n", result);
getch();
}
float f (float x)
{
return(1.0/(1.0+x*x));
}
 
Forum » Codeing » C ++ Examples of maths » Trapezoidal Rule (Trapezoidal Rule)
  • Page 1 of 1
  • 1
Search: