用c语言求一个小于100000的一个整数,要求这个数加上100后是一个完整平方数,在加上268又是一个完整平方数,请问该数有哪些?
#include <stdio.h> #include <math.h> main(){ long int i,x,y; for(i=1;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); } } }
undefined reference to `sqrt'
代码中是我是引入math.h类库的,提示没有找到!该问题为实际上没有链接math库,编译时需要加上 -lm 参数(链接math库)
通过执行 gcc -lm test02.c -o test02即可