判断任意数字是否是回文数
程序员文章站
2023-10-24 17:59:10
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("此数不是回文数.");
}
}
摘自 张仁阳专栏
上一篇: php输出全球各个时区列表的方法
下一篇: 成熟度与标准化是云采用主要壁垒