#include "conio.h"
#include "math.h"
void main ()
{
int i;
float u,l,n,h,tmp,tmp1,tmp2;
float x[50],y[50],R;
clrscr ();
printf ("Simpson's 1/3 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,tmp2=0; i
{
if (i%2 == 0)
tmp1 += y[i];
else
tmp2 += y[i];
}
R = ((h/3) * (y[0] + y[n] + (4 * tmp2)+ (2 * tmp1)));
printf ("\n\n\n\nResult = %f",R);
getch ();
}
0 comments:
Post a Comment