Thread: can someone help

  1. #1
    Registered User
    Join Date
    Mar 2013

    can someone help

    no matter what input i give the program it will output area equal to zero, I think my calculation are correct but I think it's not going through the loop or the communitcaion with my function is non-existence.
    #include <stdio.h>
    #include <math.h>
    double f(int x){
            pow(x,2 );
            return 0;
    int main(void)
            int a, b, N, width, i, sum,value, area;
            printf (" Enter the interval a an b");
            scanf ("%d\n%d", &a, &b);
            printf (" Enter the number of trapezoids you would like to use");
            scanf ("%d", &N);
            width = (b-a)/N;
          sum=(f(a) + f(b))/2;
            for (value = a + width; value < b; value += width)
                    sum += f(value);
            area = sum * width;
            printf (" The area under the curv is %d\n", area);
            return 0;

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > pow(x,2 );
    Where does this result go?

    > return 0;
    Where does this answer go?
    Does it look suspiciously like a zero to you?

    Perhaps say
    return pow(x,2 );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed