1.Using
function
#include
<stdio.h>
#include
<string.h>
int main()
{
char a[100], b[100];
printf("Enter the string to check if it
is a palindrome\n");
gets(a);
strcpy(b,a);
strrev(b);
if( strcmp(a,b) == 0 )
printf("Entered string is a
palindrome.\n");
else
printf("Entered string is not a
palindrome.\n");
return 0;
}
Method 2:
#include
<stdio.h>
main()
{
int n, reverse = 0, temp;
printf("Enter a number to check if it
is a palindrome or not\n");
scanf("%d",&n);
temp = n;
while( temp != 0 )
{
reverse = reverse * 10;
reverse = reverse + temp%10;
temp = temp/10;
}
if ( n == reverse )
printf("%d is a palindrome
number.\n", n);
else
printf("%d is not a palindrome
number.\n", n);
return 0;
}
Method 3:
Without function
#include
<stdio.h>
#include
<string.h>
int main()
{
char text[100];
int begin, middle, end, length = 0;
gets(text);
while ( text[length] != '\0' )
length++;
end = length - 1;
middle = length/2;
for( begin = 0 ; begin < middle ; begin++
)
{
if ( text[begin] != text[end] )
{
printf("Not a
palindrome.\n");
break;
}
end--;
}
if( begin == middle )
printf("Palindrome.\n");
return 0;
}