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;
}

0 comments :

Post a Comment

Spam comments will be deleted. :)

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

 
<>
TOP