/*我写了一点,但是有错误,汗*/
/*
【程序3】
题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
*/
/*
x + 100 >= 1;
y = x + 100;
y + 168 = z * z;
*/
#include "stdio.h"
#include "ctype.h"
#include "math.h"
main()
{
long int digit;
long int i;
long int x,y;
/*
printf ("请从键盘输入一个整数:");
scanf ("%ld",&digit);
for (i = 1; i <= 3; i ++) {
if (isdigit(digit) || ((digit + 100 < 1))) {
printf ("请输入正确的整数,谢谢!\n");
scanf ("%ld",&digit);
++i;
}
else if (digit + 100 >= 1) {
break;
}
}
if (isdigit(sqrt(digit + 100))) {
printf ("aaaaaa%d:",sqrt(digit + 100));
}
*/
for (i = -99; i <= 99999999; i ++) {
//x = sqrt(i + 100);
//y = sqrt(i + 268);
if ((isdigit(sqrt(i + 100))) && (isdigit(sqrt(i + 268)))) {
digit = i;
printf ("the number is%ld:",digit);
}
else {
printf ("请输入正确的整数,谢谢!\n");
continue;
}
}
}
错误警告:
Compiling...
Test3.c
C:\Documents and Settings\1\桌面\tmp\dd\Test3.c(38) : warning C4244: 'function' : conversion from 'double ' to 'int ', possible loss of data
C:\Documents and Settings\1\桌面\tmp\dd\Test3.c(38) : error C2108: subscript is not of integral type
C:\Documents and Settings\1\桌面\tmp\dd\Test3.c(38) : error C2296: '&' : illegal, left operand has type 'unsigned short *'
C:\Documents and Settings\1\桌面\tmp\dd\Test3.c(38) : warning C4244: 'function' : conversion from 'double ' to 'int ', possible loss of data
C:\Documents and Settings\1\桌面\tmp\dd\Test3.c(38) : error C2108: subscript is not of integral type
C:\Documents and Settings\1\桌面\tmp\dd\Test3.c(38) : error C2296: '&' : illegal, left operand has type 'unsigned short *'
Error executing cl.exe.
Test3.obj - 4 error(s), 2 warning(s)
------解决方案--------------------
你犯得错误是isdigit是判断字符是否数字字符,而不是判断整数
随便写了下:
- C/C++ code
#include "stdio.h" #include "ctype.h" #include "math.h" main() { long int digit; long int i; long int x,y; int flag1 = 0,flag2 = 0; for(x=-99;x<200000000;x++) { for(i=1;i<=(int)sqrt(x+100);i++) if(i*i == x+100) flag1 = 1; for(i=1;i<=(int)sqrt(x+268);i++) if(i*i == x+268) flag2 = 1; if(flag1&&flag2) break; } printf("%d\n",x); }
------解决方案--------------------
up k2eats
------解决方案--------------------