/* 判断是否为回文数字 */ #include <stdio.h> int ishuiwen(int n); /*定义第一个自定义函数判断是否回文*/ int daozhuan(int n); /*第二个自定义函数判断倒转后结果是否与原数相同*/ int main(void) { int n; printf("Enter n: "); scanf_s("%d",&n); if (ishuiwen(n)) { /*若是一个回文数字,则输出:是一个回文数字*/ printf("%dis a huiwenshuzi ",n); } else { printf("%d isn't a huiwenshuzi ",n); } } int ishuiwen(int n) { /*调用判断是否回文*/ int i; i = daozhuan(n); /*将数字顺序调转,看前后是否相同*/ if (i == n) { /*若相同返回1,不相同返回0*/ return 1; } else { return 0; } } int daozhuan(int n) { /*定义倒转数字*/ int i,j=0; i = n; while (i) { j = j*10 + i % 10; i = i / 10; /*倒转位数*/ } return j; }