trapezoidal rule

This is a discussion on trapezoidal rule within the C Programming forums, part of the General Programming Boards category; Code: I am new to c programing and I had spend 2 days on a program and I can't fix ...

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    15

    trapezoidal rule

    Code:
     I am new to c programing and I had spend 2 days on a program and I can't fix the error:
            gcc Test.c -o Test.exe
    /tmp/ccZkbk0V.o: In function `f':
    Test.c:(.text+0x2f): undefined reference to `sqrt'
    collect2: ld returned 1 exit status
    
    the program I am working in is:
    
    #include <stdio.h>
    #include <math.h>
    int f(int x){
            return (sqrt(4.0 - x*x));
    }
    int main(void)
    {
            int a, b, N, width, i, sum,value, area;
            printf (" Enter the interval a an b");
            scanf ("%d\n%d\n", &a, &b);
            printf (" Enter the number of trapezoids you would like to use");
            scanf ("%d\n", &N);
            width = (b-a)/N;
            sum=(f(a*a) + f(b*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;
    }
     
    can some one help me dig myself out of a hole

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    2,577
    Link to the math library. The math library is called "m" on most GCC and other systems.
    The option -lm is what works for most systems; that is a lowercase L not an I.

    1st Suggestion to try
    Code:
    gcc Test.c -lm -o Test.exe
    2nd Suggestion to try
    Code:
    gcc Test.c -o Test.exe -lm
    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  3. #3
    Registered User
    Join Date
    Mar 2013
    Posts
    15
    thanks you for all your help it work

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. trapezoidal rule
    By howlin in forum C Programming
    Replies: 8
    Last Post: 03-06-2012, 11:02 AM
  2. The trapezoidal rule question
    By paranoidgnu in forum C Programming
    Replies: 9
    Last Post: 04-24-2011, 09:00 AM
  3. Simpson's rule and Trapezoidal rule from fixed array
    By timwonderer in forum C++ Programming
    Replies: 1
    Last Post: 12-02-2010, 02:14 PM
  4. composite trapezoidal rule
    By Sam Robinson in forum C Programming
    Replies: 0
    Last Post: 05-19-2003, 10:01 AM
  5. Arrays and the trapezoidal rule
    By ChemistryStar4 in forum C++ Programming
    Replies: 1
    Last Post: 04-05-2003, 08:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21