sqrt函数出错,求教
//题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
void main(){ int x,y,i; for(i=0;;++i) { x=sqrt(i+100); y=sqrt(i+168); if(x*x==(i+100)&&y*y==(i+168)) { printf("X=%d\n",i); goto end; } }end:; system("pause");}#include<stdio.h>#include<math.h>void main(){ int x,y,i; for(i=0;;++i) { x=sqrt(i+100); y=sqrt(i+168); if(x*x==(i+100)&&y*y==(i+168)) { printf("X=%d\n",i); goto end; } }end:; system("pause");}
[解决办法]
#include<math.h> 添一个这个
[解决办法]
懒的看sqrt的错误了,建议楼主把 goto end 换成 break
[解决办法]
加上#include <math.h>
gcc 编译的话加上-lm如:gcc test.c -o test -lm
[解决办法]
sqrt的输入参数,返回值都为浮点数,本身就不是精确的,用int来接收误差更大。
[解决办法]
没有包含头文件吧。
[解决办法]