我最近开始学习利用C语言编程。遇到了一个问题,有所不明,因此想请教大家。
编写一个程序,用到了<math.h>的库。源程序很简单,如下:
/*分解1到10000以内的质数*/
#include<stdio.h>
#include<math.h>
int main()
{
int x,l,leap;
for(x=1;x<=10000;x++)
{
leap=1;
for(l=2;l<=(int)(sqrt(x));l++)
if(x%l==0)
{
leap=0;
break;
}
if(leap!=0)
{
printf("%d",x);
printf("\n");
}
}
return 0;
}
编译时遇到了如下错误提示:
/tmp/ccqfhW61.o: In function `main':
11.c:(.text+0x84): undefined reference to `sqrt'
collect2: ld 返回 1
对于这条错误提示不明白;这是否提示我们缺少math的库函数?
恳请大家指导
question for replying
-
- 帖子: 10
- 注册时间: 2006-05-11 11:13
- 来自: beijing normal university
- madoldman
- 帖子: 599
- 注册时间: 2006-02-27 20:19
- 来自: works system
- 联系: