#include <stdio.h>
int isPalindrome(int num) {
int reversedNum = 0;
int originalNum = num;
while (num > 0) {
int remainder = num % 10;
reversedNum = reversedNum * 10 + remainder;
num = num / 10;
}
return originalNum == reversedNum;
}
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (isPalindrome(num)) {
printf("%d is a palindrome number.\n", num);
} else {
printf("%d is not a palindrome number.\n", num);
}
return 0;
}
這段代碼實現了一個檢查回文數的功能。用戶輸入一個整數,程序會判斷這個整數是否是回文數,即從左到右和從右到左讀是相同的數字。如果是回文數則輸出"X is a palindrome number.“,否則輸出"X is not a palindrome number.”。