Write a C Program to read a string and check whether it is palindrome or not.

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
   char str[80];
   int l,i;
   clrscr();
   printf("\nEnter the string:");
   gets(str);
   printf("\nThe entered string is %s",str);
   l=strlen(str);
   for(i=0;i<l/2;i++)
   {
       if (str[i]!=str[l-1-i])
       {
     printf("\n%s is not a palindrome\n",str);
     getch();
     exit(0);
       }
    }
printf("\n%s is a palindrome",str);
getch();
}

No comments:

Post a Comment