C Program to Check Palindrome Number
This program checks whether the entered integer is a palindrome number or not by reversing its digits and comparing it with the original number.
Concept Overview
A palindrome number remains the same when its digits are reversed. For example, 121, 1331, and 1221 are palindrome numbers. The program reverses the number using arithmetic operations and compares it with the original value.
Program
#include <stdio.h>
int main() {
int num, originalNum, remainder, reversed = 0;
// Input number from user
printf("Enter a number: ");
scanf("%d", &num);
originalNum = num; // Store original value
// Reverse the number
while (num != 0) {
remainder = num % 10;
reversed = reversed * 10 + remainder;
num = num / 10;
}
// Check palindrome condition
if (originalNum == reversed)
printf("%d is a palindrome number.\n", originalNum);
else
printf("%d is not a palindrome number.\n", originalNum);
return 0;
}
Sample Output
Enter a number: 1221 1221 is a palindrome number. Enter a number: 1234 1234 is not a palindrome number.
Explanation
- The program stores the original number in a temporary variable.
- It reverses the number by repeatedly extracting digits using `%` and constructing the reverse using multiplication and addition.
- Finally, it compares the reversed number with the original number.
- If both are equal, it is a palindrome number.