题目:一个整数,若加上100后是一个完全平方数,若加上168还是一个完全平方数,请问该数是多少?
分析:不知道这数字大小是多少,不知道这样的数字有几个,程序写起来效率不会高。开始写成while(x
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #include <stdio.h> #include <limits.h> int main(void) { unsigned short x=0; //符合条件的数字 unsigned short y; unsigned short z; do { y=sqrt(x+100); //取(x+100)的平方根 z=sqrt(x+168); //取(x+168)的平方根 if(y*y==x+100&&z*z==x+168) //判断是否符合条件 { printf(" %d ",x); //打印这个数字 } x++; //累加x }while(x<SHRT_MAX); return 0; } |

Greetings! I know this is kinda off topic however , I’d figured I’d ask. Would you be interested in trading links or maybe guest writing a blog post or vice-versa? My site addresses a lot of the same topics as yours and I believe we could greatly benefit from each other. If you happen to be interested feel free to send me an e-mail. I look forward to hearing from you! Superb blog by the way!