专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > C语言

求一道算法。一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请教该数是多少

发布时间:2011-06-28 16:19:24 文章来源:www.iduyao.cn 采编人员:星星草
求一道算法。一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
/*我写了一点,但是有错误,汗*/
/*
【程序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
------解决方案--------------------
探讨
up k2eats
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: