Friday, 21 April 2017

Program to check whether string is palindrome or not

Program to check whether string is palindrome or not


#include<stdio.h>
#include<string.h>

void main()
{
          char s1[20], s2[20];
          printf("\nEnter s1: ");
          gets(s1);

          /*Copy s1 contents to s2*/
          strcpy(s2, s1);

          /*Reverse s2*/
          strrev(s2);


          /*Compare s1 and s2*/
          if(strcmp(s1, s2) == 0)
                  printf("\nString is palindrome.");
          else
                 printf("\nString is not a palindrome");


}

Output:
case 1:
Enter s1: abcde
String is not a palindrome


case 2:
Enter s1: abcba
String is palindrome.