Learn C Programming

Codes

Codes

C program is used to check if a number is palindrome or not. Now let us know that what is Palindrome String? It is a string that reads the number which has same backward and forward and it can be odd or even number. So, we can say that if the number is same from both ends then it is a palindrome number.

` ````
#include
```
int main()
{
int n, reversedInteger = 0, remainder, originalInteger;
printf("Enter an integer: ");
scanf("%d", &n);
originalInteger = n;
// reversed integer is stored in variable
while( n!=0 )
{
remainder = n%10;
reversedInteger = reversedInteger*10 + remainder;
n /= 10;
}
// palindrome if orignalInteger and reversedInteger are equal
if (originalInteger == reversedInteger)
printf("%d is a palindrome.", originalInteger);
else
printf("%d is not a palindrome.", originalInteger);
return 0;
}

` ````
Enter the number=151
Palindrome number
Now,
Enter the number=5621
not Palindrome Number
```