-1
#include <stdio.h>
#include <stdlib.h>

void main()
{
char x[10],y[10];
int i,j,k,flag=0;
printf("enter the string: ");
fgets(x,sizof(x),stdin);
for(i=0;x[i]!='\0';i++)
for(j=0,k=i;x[k]!='\0';j++,k--)
{
    y[j]=x[k];
    }
    if(x==y)
    {
        printf("the string is palindrome");
    }
    else
    {
        printf("not palindrome");
    }
}

Edited by rithish

3
Contributors
7
Replies
10
Views
5 Years
Discussion Span
Last Post by rithish
0

it is sizeof() operator, not sizof. spelling error. check it now.

0

try to check the beginning and end of the indeces of the string if equal. The index starting from the beginning to increment and the index starting at the end to decrement and comparing both of them
e.g.

       //here int i is the counter of the index from the start of the word and j from the end and n as the counter to check if the word is a palindrome
       j = strlen(string) - 1;
       for(i = 0; i <= j ; i++,j--){                   
           if(string[i]!=string[j]){                
               n=1; //counter tells that the sting is currently not a palindrome                                 
               break;  //once found that character doesn't matches it breaks from the loop                             
           }
           if(string[i]==string[j]){                
               n=0; //counter tells that the sting is currently a palindrome                                
           } 
       } 

then print the word is not a palindrome if the value of n is 1 else a palindrome

Edited by zeroliken

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.