PROBLEM with my program. im confused

OKAY THE FOLLOWING IS WHAT THEY ARE ASKING ME TO DO AND MY RPOGRAM. I HAVE ONLY FINISHED THE FIRST LOOP AND HAVE NOT STARTED ON THE SECOND. I JUST WANT TO KNOW WHAT I AM DOING WRONG BECAUSE I AM NOT GETTING THE CORRECT ANSWER.
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 the
program based on trapezoidal rule discussed in class (Problem w4-10.c
in the lecture notes week4.txt).

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.


#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*pow(cos(x),2)+0.25;
sum= -0.5 * y;

for(k=0; k<=n_trap; k++)
{
x=a+k*del_x;
y=0.5*pow(cos(x),2)+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);
.....
Use [code] blocks, please.

And try brushing up on your Calculus. I'm not 100% sure what you're doing here, but it can't possibly be right.
http://upload.wikimedia.org/math/2/3/d/23d5bd7f90bbfbf2e6876bf8d444e2b2.png

EDIT:
http://en.wikipedia.org/wiki/Trapezoidal_rule

Welcome to the forum.

-Albatross
Last edited on
And please don't type all in caps. It's very irritating, not to mention rude.
Topic archived. No new replies allowed.