今天做 ACM 题时遇到的问题,请教各位!
题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?我自己的代码是:
程序代码:# include <stdio.h>
# include <math.h>
void main()
{
int num = 0;
long x, y, i;
for (i = 1; i < 100000; i++)
{
y = i + 100;
x = i + 268;
if ((y == sqrt(y) * sqrt(y)) && (x == sqrt(x) * sqrt(x)))
{
printf("The number is %ld", i);
num++;
}
}
printf("The total is %d", num);
}但是出错了!!!!
正确答案的代码在下面,我感觉我们两个的答案都一样啊
!!!但是我的却是错误的,为什么啊???
望大神指点一二~~~
程序代码:# include <stdio.h>
# include <math.h>
void main()
{
long int i, x, y, z;
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);
}
}






