问题及代码:
/*
*copyright(c)2016,烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:test.cpp
*作者:崔青青
*完成日期:2016年3月17号
*问题描述:有等式[#*(#3+#)]的平方为8##9,请确定#代表的数字。
*输入:无
*程序输出:#代表的数字。
*/
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int a,b,c,d,e,sum;
for(a=0;a<=9;a++)
{
for(b=0;b<=9;b++)
{
for(c=0;c<=9;c++)
{
for(d=0;d<=9;d++)
{
for(e=0;e<=9;e++)
{
sum=a*(b*10+3+c);
if (sum*sum==8000+d*100+e*10+9)
{
cout<<"等式为:["<<a<<"×("<<b<<"3+"<<c<<")]^2=8"<<d<<e<<"9)"<<endl;
}
}
}
}
}
}
return 0;
}
运行结果:
知识点总结:
熟练掌握穷举法。
学习心得:
找准条件,思考全面。