我试图在C编程中找到平方根.但我得到的错误是对sqrt的未定义引用.我的代码是:
#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);
}
Run Code Online (Sandbox Code Playgroud)
如果您正在使用gcc进行编译,则libm.a需要提供数学函数,您需要使用它们单独链接-lm
gcc -Wall main.c -o my_prog -lm
Run Code Online (Sandbox Code Playgroud)