閱讀math.h的文檔,似乎我應該做的就是包含math.h,並使用包含的數學函數,如sqrt。問題是我試圖在我的程序中使用sqrt時出現以下錯誤。我試過math.sqrt,但那也沒用。任何想法我做錯了什麼?在C中使用math.h sqrt函數
undefined reference to `sqrt'
...
#include <stdio.h>
#include <math.h>
int main (int argc, char *argv[])
{
int a, b;
a = 1;
b = 5;
if (a < sqrt (b))
printf("1 < sqrt(5)");
return 0;
}
也許用'-lm'選項 – BLUEPIXY
我知道它說'sin',但它是任何數學函數相同。 – hammar