温馨提示×

C语言实现回文数字的有效性检查

小樊
83
2024-08-08 04:21:41
栏目: 编程语言

#include <stdio.h>

int isPalindrome(int num) { int reversed = 0; int original = num;

while (num > 0) {
    reversed = reversed * 10 + num % 10;
    num = num / 10;
}

if (reversed == original) {
    return 1;
} else {
    return 0;
}

}

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;

}

0