1.用数组实现
#include<stdio.h>
int Ishuiwen(long n)
{
int a[20];
int start = 0;
int end = 0;
int index = 0;
while(n != 0)
{
a[index] = n % 10;
n /= 10;
index++;
}
end = index - 1;
while(start < end)
{
if(a[start] != a[end])
{
return 0;
}
start++;
end--;
}
return 1;
}
void main()
{
long n = 12321;
printf("%d",Ishuiwen(n));
}
2.数字实现方法
#include<stdio.h>
int Ishuiwen(long n)
{
int temp,sum=0;
temp = n;
while(n) //这段的意思是将数n倒过来放到sum,如果sum等于数n,那么就是回文数了
{
sum = sum * 10 + n % 10;
n /= 10;
}
if(temp == sum)
{
return 1;
}
else
{
return 0;
}
}
void main()
{
long n = 11;
printf("%d",Ishuiwen(n));
}