0

i have a problem with my coding to fing wether given string is palindrome or not
without using strcmp(); and srtrev();

it returns "the string is not a palindrome " for all string
the

#include<stdio.h>
#include<string.h>
 void main()
 { 
   int n,i,j;
   char a[100];
   scanf("%s",a);
    
  n=strlen(a);
       printf("the length ia%s,%d\n",a,n);
       
      
        while(i<=j)
        { i=0;j=n;
          if(a[i]==a[j])
           { 
            i++;
            j--;
           }
          else
            break; 
        }
        
        if(i==j)
        {
        printf("the no is palindrome\n");
        }
        else
        {
        printf("this is not palindrome\n");
        }
        
 }
2
Contributors
4
Replies
6
Views
7 Years
Discussion Span
Last Post by Shankye
0

I think you checking even new line char '\n'..

Try to trim newline char and than check for palidrome ..

0

And i think i and j must be assigned before loop ..

Try using this code ..

i=0;
      j=n-1;   // You may be going wrong here 

      while(i<j)
      { 
         if(a[i]==a[j])
         {
           i++;
           j--;
         }
         else
           break; 
       }
 // Remaining code as it is ..
This topic has been dead for over six months. 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.