Question : Write a C Program to check whether a number is palindrome or not.
/*
Write a C Program to check whether a number is palindrome or not.
*/
#include <stdio.h>
int main()
{
int n, reversedN = 0, remainder, originalN;
printf("Enter an integer: ");
scanf("%d", &n);
originalN = n;
// reversed integer is stored in reversedN
while (n != 0)
{
remainder = n % 10;
reversedN = reversedN * 10 + remainder;
n /= 10;
}
// palindrome if orignalN and reversedN are equal
if (originalN == reversedN)
{
printf("%d is a palindrome.", originalN);
}
else
{
printf("%d is not a palindrome.", originalN);
}
return (0);
}
OUTPUT :
Enter an integer: 1001
1001 is a palindrome.
Thank you very much for reading carefully, if you have any other questions, you can share it with us through comments, if this information was important to you, please let us know through comments.
Please do comment and share.
Thank You.
Please do comment and share.
Thank You.
No comments:
Post a Comment