问题描述:打印所有不超过n(n<256)的,其平方具有对称性质的数。如11*11=121。
分析:对称性质就是对这个数交换低位和高位,得到新的数和原数相等。
解题思路:直接将低位放在高位,高位放低位求解。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char** argv) {
unsigned int n;
for (int i = 1; i < 256; i++) {
int power = 0;
power = n = i * i;
int num = 0;
int temp = 0;
while (n) {
temp = n % 10;
num = temp + num * 10;
n /= 10;
}
if (num == power) {
cout << i << endl;
}
}
system("pause");
return 0;
}