判断任意数字是否是回文数
程序员文章站
2022-06-05 14:26:42
void main()
{
long num,smallnum;
 ...
void main()
{
long num,smallnum;
scanf("%d",&num);
smallnum = num;
int start=1;
int count=0;
do{
start*=10;
count++;
}while(num%start!=num);
printf("本数是%d位\n",count);
int i;
int yes=1;
if(count%2==0){
yes=0;
}
int loopcount = count/2;
int innercounter=1;
int bigsum=1;
int smallsum=1;
for(i=1;i<=loopcount;i++){
smallsum=1;
for(innercounter=1;innercounter<=i;innercounter++){
smallsum = smallsum*10;
}
bigsum=1;
for(innercounter=1;innercounter<=(count-i);innercounter++){
bigsum = bigsum*10;
}
int small = smallnum%(smallnum/10);
smallnum = smallnum/=10;
int big = num/bigsum;
num = num%bigsum;
if(big!=small){
yes=0;
break;
}
}
if(yes==1){
printf("此数是回文数.");
}else{
printf("此数不是回文数.");
}
}
摘自 张仁阳专栏
{
long num,smallnum;
scanf("%d",&num);
smallnum = num;
int start=1;
int count=0;
do{
start*=10;
count++;
}while(num%start!=num);
printf("本数是%d位\n",count);
int i;
int yes=1;
if(count%2==0){
yes=0;
}
int loopcount = count/2;
int innercounter=1;
int bigsum=1;
int smallsum=1;
for(i=1;i<=loopcount;i++){
smallsum=1;
for(innercounter=1;innercounter<=i;innercounter++){
smallsum = smallsum*10;
}
bigsum=1;
for(innercounter=1;innercounter<=(count-i);innercounter++){
bigsum = bigsum*10;
}
int small = smallnum%(smallnum/10);
smallnum = smallnum/=10;
int big = num/bigsum;
num = num%bigsum;
if(big!=small){
yes=0;
break;
}
}
if(yes==1){
printf("此数是回文数.");
}else{
printf("此数不是回文数.");
}
}
摘自 张仁阳专栏
上一篇: 六一关注儿童健康 孩子吃五食物性早熟