首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

大家看看小弟我这个函数错在那里

2012-03-12 
大家看看我这个函数错在那里?#includestdio.h#includestdlib.h#includemath.hintmain(intargc,char*

大家看看我这个函数错在那里?
#include   <stdio.h>
#include   <stdlib.h>
#include   <math.h>

int   main(int   argc,char   *argv[])
{
          int   i,k,m;
        scanf( "%d ",&m);
        k=sqrt(m);
        for(i=2;i <=k;i++)
        {
                if(m%i==0)   break;
        }
        if(i==k+1)   printf( "%d   is   a   prime   number! ",m);
        else   printf( "%d   is   not   a   prime   number! ",m);
        return   0;
}
出现编译错误:
/tmp/cczAvUqr.o(.text+0x3e):   In   function   `main ':
:   undefined   reference   to   `sqrt '
collect2:   ld   returned   1   exit   status
请问各位大侠我错在哪里?


[解决办法]
我明白了,楼主是在linux下编译的

通常情况下,gcc是不会主动链结数学库的,要在最后面加 -lm
[解决办法]
% gcc -o foobar foobar.c -lm

热点排行