Our social:

String Palindrome C Program

A string is said to be palindrome if it remains same after reversing it. That is, it is read same in both ways. For example: MADAM, 1001, 111 etc. are palindromes.



The following C Program will check a string is palindrome or not ! 

#include <stdio.h>
#include <string.h>

int main()
{
    int i, j, len, palindrome = 1;
    char str[80];
    printf("Enter a string: ");
    gets(str);
    len = strlen(str);
    for(i=0, j=len-1; i<j; i++, j--){
        if(str[i] != str[j]){
            palindrome = 0;
            break;
        }
    }
    if(!palindrome)
        printf("%s is not a palindrome!\n",str);
    else
        printf("%s is a palindrome!\n",str);
    return 0;
}