输出1到n以内所有的二进制回文数
#include <stdio.h>
#define SIZE 50
typedef enum bool Bool;
enum bool {
false, true
};
int main()
{
int n, i, j;
Bool flag = false;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
int a[SIZE] = {0};
j = 0;
int tmp = i;
while (tmp != 0)
{
a[j++] = tmp % 2;
tmp /= 2;
}
int x;
for (x = 0; x < j; x++) {
if (a[i] != a[j-x-1]) {
flag = true;
break;
}
}
if (flag == false) {
printf("%d\n", i);
}
}
return 0;
}
参考:https://zhidao.baidu.com/question/585449561561135765.html