Codes for Trapezoidal Rule in C and C++
Tuesday, October 15, 2013
#include<stdio.h>
#include<conio.h>
#include<math.h>
float fn(float x)
{
sqrt(x);
return sqrt(x);
}
main()
{
int i,n;
float a,b,s=0,y=0,h;
printf("Enter the no of interval =");
scanf("%d",&n);
printf("Enter the lower limit=");
scanf("%f",&a);
printf("Enter the upper limit=");
scanf("%f",&b);
h=(b-a)/n;
for(i=1;i<=n-1;i++)
{
s=s+fn(a+i*h);
}
y=(fn(a)+fn(b)+2*s)*h/2;
printf("the value of y is=%f",y);
getch();
}
-this source codes belongs to: the author of wbutassignmenthelp :)
-this source codes is ready for copy-paste to any IDE/compilers for C/C++. The quotations from the original website source confuse the compilers, I've already change them to the original quotation :)
additional tags: trapezoidal rule for C, trapezoidal rule for Cplusplus, C++, codes for Trapezoidal, trapezoidal source codes
Sharing is so Easy: |
Labels:
C Programming,
C++,
Programming,
sample programs