C program to check whether an input number is a palindrome or not.
Introduction:
A palindrome is a sequence of characters that reads the same way forwards and backward. For example, "MADAM" is a palindrome because it reads the same way in both directions. In this blog post, we will discuss how to write a C program to check whether an input number is a palindrome or not.
Before we start with the program, we need to understand the logic behind checking if a number is a palindrome. To check whether a number is a palindrome or not, we need to reverse the number and check if the reversed number is the same as the original number. If they are the same, the number is a palindrome; otherwise, it is not.
Now, let's look at the code:
int main()
{
int num,n=0,rev=0,d;
printf("Enter any number\n");
scanf("%d",&num);
n=num;
while(num>0)
{
d=num%10;
rev=rev*10+d;
num=num/10;
}
if(n==rev)
printf("The entered number is palindrome\n");
else
printf("The entered number is not palindrome\n");
return 0;
}
Output:
Conclusion:
In conclusion, we have discussed how to write a C program to check whether an input number is a palindrome or not. The program uses a simple algorithm to reverse the number and compare it with the original number to determine if it is a palindrome or not. By understanding the logic behind the program, you can modify it to check if a string or a word is a palindrome as well.
You can also Read:
No comments:
Post a Comment