12. aabb

题目:

 输出所有形如aabb的4位完全平方数(即前两位数字相等, 后两位数字也相等)

思路:

用枚举法列出所有可能组合,然后判断该数是否为完全平方数。并且 a 从 1 开始, b 从 0 开始。 

代码:

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
for (int a = 1; a <= 9; ++a) {
for (int b = 0; b <= 9; ++b) {
int n = a * 1100 + b * 11;
int m = floor(sqrt(n) + 0.5);
if (m*m == n) {
cout << n << endl;
}
}
}

return 0;
}
原文地址:https://www.cnblogs.com/Hello-Nolan/p/12111390.html