close

/*
輸入一 1000以內的整數,判斷此整數是否為回文; 123反過來321不是回文; 121反過來121 是回文; 
*/
#include <stdio.h>
#include <stdlib.h>
int main()
{
   int a,b,c,d,e;  // a:輸入的整數  b:a的百位數, c:a的十位數 d:a的個位數  e:a的反轉 (=100*d+10*c+b;)
   int t;
   scanf("%d",&a); // 設 a=121 (or 123)
   t=a;
   b=(int)t/100;   // b=(int)121/100=1 or (int)123/100=1
   t=t-100*b;      // t=121-100*1=21   or t=123-100*1=23 
   c=(int)t/10;    // c=(int)21/10=2;  or c=(int)23/10=3; 
   t=t-10*c;       // t=21-10*2=1;  or t=23-10*2=3;
   d=t;            //d=1  or d=3;
   
   //printf("test %d %d %d %d %d",a,b,c,d,e);
   e=100*d+10*c+b;    //e=100*1+10*2+1=121   or e=100*3+10*2+1=321
   
   if(a==e) printf("%d 是回文",a);  // 121 是回文  123 不是回文
   else printf("%d!=%d 不是回文",a,e); 
   
   printf("\n\n"); system("pause");

    return (1);

}

arrow
arrow
    全站熱搜

    tatar 發表在 痞客邦 留言(0) 人氣()