C Program to Check Whether a Number is Palindrome or Not
You will discover how to determine whether or not a user-entered number is a palindrome in this example.
You should be familiar with the following C programming concepts in order to comprehend this example:
Program to Check Palindrome
#include <stdio.h>
int main() {
int n, reversed = 0, remainder, original;
printf("Enter an integer: ");
scanf("%d", &n);
original = n;
// reversed integer is stored in reversed variable
while (n != 0) {
remainder = n % 10;
reversed = reversed * 10 + remainder;
n /= 10;
}
// palindrome if orignal and reversed are equal
if (original == reversed)
printf("%d is a palindrome.", original);
else
printf("%d is not a palindrome.", original);
return 0;
}
Output
Enter an integer: 1001 1001 is a palindrome.
Post a Comment
0 Comments