# C語言中判斷一個數是否是迴文數

1，流程；（知道程式是按照怎樣的順序啟動並執行）

2，功能；（理解程式的作用）

3，試數；（我個人簡單的理解為測試過程，把自己當作電腦去執行程式）

/*

2012年4月20日 10:36:23

*/

#include <stdio.h>

int main(void)

{

int val; //存放待判斷的資料

int m;

int sum = 0;

printf("請輸入您需要判斷的數字：\n");

scanf("%d",&val);

m = val;

/*這一塊是核心代碼塊：

sum每更新一次，m值去掉最後一位同時更新

*/

while (m)

{

sum = sum*10 + m%10;

m /= 10;

}

if (sum == val)

printf("Yes!\n");

else

printf("No!\n");

return 0;

}

/*

*/

1234

1 -> m = val = 1234; sum = 0 + 1234%10 = 4; m = 1234/10 =123;

2 -> m = 123; sum = 40 + 123%10 = 40+3 = 43; m = 123/10 = 12;

3 -> m = 12; sum = 430 + 12%10 = 432; m = 12/10 = 1;

4 -> m = 1; sum = 4320 + 1%10 = 4321; m = 1/10 = 0;

false

12321

1 -> m = val = 12321; sum = 0 + 12321%10 = 1; m = 12321/10 = 1232;

2 -> m = 1232; sum = 10 + 1232%10 = 12; m = 1232/10 = 123;

3 -> m = 123; sum = 120 + 123%10 = 123; m = 123/10 = 12;

4 -> m = 12; sum = 1230 + 12%10 = 1232; m = 12/10 = 1;

5 -> m = 1; sum = 12320 + 1%10 = 12321; m = 1/10 = 0;

false

## E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

## Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

## Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth \$300-1200 USD