-
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
-
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.
-
thanks you for all your help it work