this is what i am suppose to do.:
Scan two doubles a and b (a<b).
Integrate numerically y=0.5*cos^2(x)+0.25 from x=a to x=b.
Use two do/while statements to continue the
calculations for different n_trap and different a and b. For
example, use ask=1 to continue calculations for different n_term
within the inner do/while loop, and ask=0 to exit that loop.
Use flag=1 to continue calculations for different a and b
within the outer do/while loop, and flag=0 to exit that loop.
and this is my program so far. btw im only doing the first part havent tried the flag part because im confused
#include <stdio.h>
#include <math.h>
main ()
{
double a, b, y, del_x, Integral, x, sum;
int flag, k, n_trap, ask;
printf("Scan a and b:");
scanf("%1f %1f %1f", &a, &b);
do
{
printf("Enter the number of trapezoids:\n");
scanf("%d", &n_trap);
del_x = (b-a)/(double)n_trap;
printf("n_trap =%d\t del_x =%g\n", n_trap, del_x);
x=a;
y=0.5*cos(x)*cos(x)+0.25;
sum= -0.5 * y;
for(k=0; k<=n_trap; k++)
{
x=a+k*del_x;
y=0.5*cos(x)*cos(x)+0.25;
sum += y;
}
sum -= 0.5*y;
sum += del_x;
printf("Integral = %f\n", sum);
printf("Would you like to continue with another n_trap? y=1/n=0\n");
scanf("%d", &ask);
}
while (ask == 1);
//while (ask !=1 0);
}