Translate

Tuesday, June 7, 2016

Write a program to check whether a given string is palindrome or not in C.

#include<stdio.h>
#include<conio.h>
main()
{
      char ch[20];

      int a=1,b=0,c,d=0;

      printf("Enter the string=");

      scanf("%s",&ch);

      while(ch[a]!='\0')  // count the length of string
      {
         a++;
      }

      for(c=a-1; c>=0; c--)
      {
         if(ch[c]-ch[b]==0)
         {      
           d=0;
           }
           else
           {
               d=d+1;
               break;
               }
               b++;
               }
               if(d==0)
               {
                       printf("string is palindrome");
                       }
                       else
                       {
                           printf("string is not palindrome");
                           }            
      getch();
      }

No comments:

Post a Comment