当前位置:编程学习 > C/C++ >>

判断任意数字是否是回文数

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("此数不是回文数."); 
    } 


摘自 张仁阳专栏
补充:软件开发 , C语言 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,