皓月星空

导航

3.一个数x加上100是一个完全平方数,再加上一个168又是一个完全平方数

/*
* 一个数x加上100是一个完全平方数,再加上一个168又是一个完全平方数,
*问该数是多少
*/
#include <stdio.h>
#include <math.h>


int main(int argc, char const *argv[])
{
    int x,i,j;
    //遍历0-1000的数
    for(x = 0;x <= 1000;x++)
    {
        i = sqrt(100+x);
        j = sqrt(168+x);
  
        if(i*i == 100+x && j*j == 168+x)
        {
            printf("%d\n",x);
        }
    }
    return 0;
}

注意使用gcc的时候要添加-lm,让系统知道你要调用math.h库文件

posted on 2021-05-08 15:43  皓月星空  阅读(108)  评论(0编辑  收藏  举报