3

I am trying to find the square root in C programming. But I am getting error as undefined reference to the sqrt. My Code is:

#include<stdio.h>
#include<math.h>
void main(void){
int x;
int y;
printf("Enter two number numbers");
scanf("%d", &x);
scanf("%d", &y);
int result;
result = ( x * x ) + ( y * y );
double finalresult = sqrt(result);
printf("%f\n", finalresult);
}
Jaspreet Deol
  • 115
  • 1
  • 1
  • 12

1 Answers1

9

If you're compiling with gcc, math functions are provided by libm.a which you need to link separately using -lm

gcc -Wall main.c -o my_prog -lm
simonc
  • 41,632
  • 12
  • 85
  • 103