#include <stdio.h>
#include <math.h>
int main()
{
int x, y, x1, x2, y1, y2;
float distance;
//take the 1st points coordinates x axis and y axis
printf("Enter the coordinates of 1st point: ");
scanf("%d %d", &x1, &y1);
//take the 2st points coordinates x axis and y axis
printf("Enter the coordinates of 2nd point: ");
scanf("%d %d", &x2, &y2);
x = x2 - x1;
y = y2 - y1;
distance = sqrt((x * x) + (y * y));
//display result
printf("Distance = %.2f", distance);
return 0;
}
when i compile the program an error message is shown in the terminal window.
/usr/bin/ld: /tmp/cc8GnBrR.o: in function 'main': distance2.c:(.text+0xa4): undefined reference to 'sqrt' collect2: error: ld returned 1 exit status
is there a permanent solution for this problem other than "gcc filename.c -o filename -lm"
-lm
, period. – Antti Haapalasqrt
the standard<math.h>
header declares the function, but the definition is in them
library, which you need to link with using the-l
option. – Some programmer dude