PALINDROME NUMBER PROGRAM IN C
In this program you will learn to check whether entered number is palindrome or not.
A number is palindrome if and only if the reverse of that number is equal to original number .
Example:
> 121 is palindrome.
> 1001 is palindrome.
> 19090 is not palindrome.
Program to check palindrome:
//check whether entered number is palindrome or not
#include<stdio.h>
int main( )
{
int num, reverse_num=0, rem, temp;
printf("Enter the number :");
scanf("%d",&num);
temp=num;
while(num!=0)
{
rem=num%10;
reverse_num=reverse_num*10+ rem;
num= num/10;
}
if(temp== reverse_num)
{
prinf("%d is palindrome", temp);
}
else
{
printf("%d is not palindrome",temp);
}
return 0;
}
#include<stdio.h>
int main( )
{
int num, reverse_num=0, rem, temp;
printf("Enter the number :");
scanf("%d",&num);
temp=num;
while(num!=0)
{
rem=num%10;
reverse_num=reverse_num*10+ rem;
num= num/10;
}
if(temp== reverse_num)
{
prinf("%d is palindrome", temp);
}
else
{
printf("%d is not palindrome",temp);
}
return 0;
}
Output:
Enter the number:121
121 is palindrome.
121 is palindrome.
Try this code by your own. If you have any doubts , then feel free to drop a comment. I'll be happy to answer your questions in the comment section.
keep coding.
Comments
Post a Comment