#include<stdio.h>
int main()
{
int num,r,sum=0,temp;
printf("Enter a
number: ");
scanf("%d",&num);
temp=num;
while(num)
{
r=num%10;
num=num/10;
sum=sum*10+r;
}
if(temp==sum)
printf("It is a palindrome");
else
printf("It is
not a palindrome");
return 0;
}
output:
Enter a number: 191
It is a palindrome
____________________________________________________________
Code 2:C-Program to check for palindrome using for loop
for(temp=num;num!=0;num=num/10)
{
____________________________________________________________
____________________________________________________________
Code 2:C-Program to check for palindrome using for loop
#include<stdio.h>
int main()
{
{
int num,v,sum=0,temp;
printf("Enter a
number: ");
scanf("%d",&num);
for(temp=num;num!=0;num=num/10)
{
v=num%10;
sum=sum*10+v;
}
if(temp==sum)
printf("IT is a
palindrome");
else
printf("IT is
not a palindrome");
return 0;
}
output:
Enter a number: 191
IT is a palindrome
____________________________________________________________
Code 3: C program to find palindrome numbers in given Range
#include<stdio.h>
int main()
{
int num,v,sum,temp;
int min,max;
printf("Enter
the minimum range: ");
scanf("%d",&min);
printf("Enter
the maximum range: ");
scanf("%d",&max);
printf("Palindrome
numbers in given range are: ");
for(num=min;num<=max;num++)
{
temp=num;
sum=0;
while(temp){
v=temp%10;
temp=temp/10;
sum=sum*10+v;
}
if(num==sum)
printf("%d
",num);
}
return 0;
}
output:
Enter the minimum range:1
Enter the maximum range:20
Palindrome numbers in given range
are: 1 2 3 4 5 6 7 8 9 11
____________________________________________________________
Code 4:C-Program to check for palindrome using using recursion
#include<stdio.h>
int
checkPalindrome(int);
int main()
{
int num,sum;
printf("Enter a
number: ");
scanf("%d",&num);
sum
= Palin(num);
if(num==sum)
printf("IT is a palindrome");
else
printf("IT is
not a palindrome");
return 0;
}
int Palin(int num)
{
{
static int sum=0,v;
if(num!=0){
v=num%10;
sum=sum*10+v;
Palin(num/10);
}
return sum;
}
output:
Enter a number:192
IT is not a palindrome
No comments:
Post a Comment