5 Aug 2019

  • August 05, 2019
  • Amitraj



Palindrome number in C

A palindrome number is a which remains the same on reversal. For example, some palindrome numbers are 8, 121, 212, 12321, -454. To check whether a number is a palindrome or not first we reverse it and then compare the number obtained with the original number, if both are same then the number is palindrome otherwise not.

Check palindrome number algorithm
To test if a number is palindrome or not, do the following steps:

1. Get the number from a user.

2. Reverse it.

3. Compare it with the number entered by the user.

4. If both are the same then print palindrome number else print not a palindrome number.

/*   C Program to verify given no. is Palindrome or not */  


http://codevidyalay.blogspot.com

#include<stdio.h>
int main()
{
int n,r,m,sum=0;
printf("Enter a no:");
scanf("%d",&n);

m=n;
while(n>0)
{
r=n%10;
sum=sum*10+r;
n=n/10;
}

if(sum==m)
printf("Palindrome");
else

printf("Not palindrome");
return 0;
}


INPUT/OUTPUT:
Enter a no:123
Not palindrome

Translate

Popular Posts