回文数问题(请哪位用C给我编个程序)
Description 若一个数(首位不为0)从左到右读与从右到左读都是一样,这个数就叫做回文数,例如12521就是一个回文数。
给定一个正整数,判断它是否是回文数。
Input
一个正整数
Output
若是回文数,输出YES,否则输出NO
Sample Input
12521
Sample Output
YES
Source
程序代码:#include <stdio.h>
#include <math.h>
int check_out(int);
int main(void)
{
int n;
while (scanf("%d", &n) != EOF)
if (check_out(n))
puts("YES");
else
puts("NO");
return 0;
}
int check_out(int n)
{
int i = (int)ceil(pow(10, (int)log10(n)));
int j = 1;
while (i > j) {
if (n / i % 10 != n / j % 10)
return 0;
i /= 10;
j *= 10;
}
return 1;
}

程序代码:#include <stdio.h>
#define IS 1
#define NOT 0
int check_out(unsigned);
int main(void)
{
unsigned n; // 负数应该不能作为回文数判断吧?
while (scanf("%u", &n) != EOF)
check_out(n) == IS ? puts("YES") : puts("NO");
return 0;
}
int check_out(unsigned n)
{
char buffer[10 + 1]; // 4294967295 + '\0'
int begin = 0;
int end = sprintf(buffer, "%u", n) - 1;
while (begin < end) {
if (buffer[begin] != buffer[end])
return NOT;
begin++;
end--;
}
return IS;
}
