Write a C program to determine if the given string is a palindrome (or) not.

Algorithm:

Step 1: Start
Step 2: read the string
Step 3: store reverse of the given string in a temporary string
Step 4: compare the two strings
Step 5: if both are equal then print palindrome
Step 6: otherwise print not palindrome
Step 7: Stop

Program:

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
   char str[20];
   int i, l, f = 0;
   clrscr();
   printf("Enter any string\n");
   gets(str);
   l = strlen(str);
   for(i = 0; i <= l - 1; i++)
   {
      if(str[i] == str[l - 1 - i])
      f = f + 1;
   }
   if(f == l)
   {
      printf("The string is palindrome");
   }
   else
   {
      printf("The string is not a palindrome");
   }
   getch();
}

Input & Output:

Enter  any string  
malayalam
The string is a palindrome