在linux中用gcc编译器编写c语言代码时,不能使用数学函数(math.h),要在后面加上参数-lm,才能编译通过;如下实例:
root~$ gcc 3.c -lm
运行结果:
21
261
1581
编译:/*************************************************************************
> File Name: 3.c
> Author: pengshp
> Mail: pengshp3@outlook.com
> Created Time: 2015年04月18日 星期六 14时28分29秒
************************************************************************/
#include<stdio.h>
#include<math.h>
int main()
{
long int i,x,y,z;
for(i=0;i<100000;i++)
{
x=sqrt(i+100);
y=sqrt(i+268);
if(x*x==i+100&&y*y==i+268)
printf("\n%ld\n",i);
}
return 0;
}
root~$ gcc 3.c -lm
运行结果:
21
261
1581