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

Recommended Answers

All 4 Replies

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

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

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 ..

thank you

Welcome n hope your problem solved ..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.