帮我编程C语言的程序

来源:百度知道 编辑:UC知道 时间:2024/06/25 11:58:02
一个整数,它加上100后是一个完全平方数,再加上168,又是一个完全平方数,请问该数是多少

??这个要用很长时间算的, 是正整数还是负整数??我猜是个负的, 用loop 肯定能解决,不过。。 时间用的很长的。。。我学过vb和java 。。 c么没学过。。。 不用loop的话我觉得是解决不掉的。

#include "math.h"
main()
{
int i;
i=1;
while(1)
{
if((int)sqrt(i+100)*(int)sqrt(i+100)==i+100)
if((int)sqrt(i+168)*(int)sqrt(i+168)==i+168)
break;
i++;
}
printf("%d\n",i);
}

156

// ss.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "math.h"
#include "iostream"
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
double i;
i=1;
while(1)
{
if((int)sqrt(i+100)*(int)sqrt(i+100)==(i+100))
if((int)sqrt(i+168)*(int)sqrt(i+168)==(i+168))
break;
i++;
}
cout<<i<<endl;
}

#include <iostream.h>
#include <math.h>
#include