题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
程序分析:像这样题型我们只能用数值带入去试,幸好我们有计算机。先把这个限定到100000之内,调用系统函数sqrt()开方,分别求出这两个temp1和temp2,然后在对他们平方比较是否和原来数相等
#include <stdio.h>
#include <math.h>
int main(int argc, const char * argv[])
{
long i,temp1,temp2;
for (i=0; i<100000; i++) {
temp1 = sqrtf(i+100);
temp2 = sqrtf(i+100+168);
if ((temp1*temp1 == i+100) && (temp2*temp2 == i+100+168)) {
printf("--------> %ld\n",i);
}
}
return 0;
}
#include <