首页 > 代码库 > c语言基础-回文数复习

c语言基础-回文数复习

# include<stdio.h>


int main(void)

{

int sum = 0, val, m;


printf("请输入一个随机整数:");

scanf("%d",&val);

m=val;


while (m){

sum= sum*10 + m%10;//(理解举例:m==123,sum==3*10^2 + 2*10^1 +3*10^0)

m/= 10;

}


if (sum == val){

printf("%d是回文数",val);

}else

{

printf("%d不是回文数",val);

}



return 0;

}


c语言基础-回文数复习