#include "conio.h"
#include "math.h"
void main ()
{
int i;
float u,l,n,h,tmp,tmp1;
float x[50],y[50],R;
clrscr ();
printf ("Trapezoidal Rule:\n\n");
printf ("\n-------------------------------------\n\n\n");
printf ("Enter Upper Limit: ");
scanf ("%f",&u);
printf ("\n\n-------------------------------------\n\n\n");
printf ("Enter Lower Limit: ");
scanf ("%f",&l);
printf ("\n\n-------------------------------------\n\n\n");
printf ("Enter number of steps: ");
scanf ("%f",&n);
h = (u - l) / n;
clrscr ();
printf ("x\t\tf(x)");
for (i=0; i<=n; i++)
{
x[i] = l + (i * h); /* Here, The equation is [ e powerof (square root of x) ] */
tmp = sqrt (x[i]); /* You can put your own equation here */
y[i] = exp (tmp);
printf ("\n\n%f\t%f",x[i],y[i]);
}
for (i=1,tmp1=0; i
{
tmp1 += y[i];
}
R = ((h/2) * (y[0] + y[n] + (2 * tmp1)));
printf ("\n\n\n\nResult = %f",R);
getch ();
}
0 comments:
Post a Comment