c语言

C语言实现回文数字的校验功能

小樊
82
2024-08-08 04:15:42
栏目: 编程语言

#include <stdio.h>

// Function to check if a number is a palindrome int isPalindrome(int num) { int originalNum = num; int reverseNum = 0;

// Reversing the number
while (num > 0) {
    int digit = num % 10;
    reverseNum = reverseNum * 10 + digit;
    num = num / 10;
}

// Checking if the original number is equal to the reversed number
if (originalNum == reverseNum) {
    return 1; // Return 1 if palindrome
} else {
    return 0; // Return 0 if not palindrome
}

}

int main() { int num;

// Input number from user
printf("Enter a number: ");
scanf("%d", &num);

// Check if the number is a palindrome
if (isPalindrome(num)) {
    printf("%d is a palindrome number.\n", num);
} else {
    printf("%d is not a palindrome number.\n", num);
}

return 0;

}

0
看了该问题的人还看了