C 程序:检查数字是否是回文
原文:https://www.studytonight.com/c/programs/loop/palindrome-program
下面是一个检查数字是否是回文的程序。
一个回文是一个数字或者一个字符串,从前面和后面看都是相似的。例如:121 或 Oppo 等。
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, c, s = 0;
clrscr();
printf("Enter a number:\t");
scanf("%d", &a);
c = a;
// the number is reversed inside the while loop.
while(a > 0)
{
b = a%10;
s = (s*10)+b;
a = a/10;
}
// here the reversed number is compared with the given number.
if(s == c)
{
printf("The number %d is a palindrome", c);
}
else
{
printf("The number %d is not a palindrome", c);
}
getch();
}
输入数字:121 数字 121 是回文