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);
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With