Check Palindrome or Not in C


This program is about checking and print the given string is palindrome or not using for loop and if conditions.

Source Code

#include<stdio.h>
int main()
{
   int i,n=0,s=0;
   char a[100],b[100];
   printf("\nEnter the string:");
   gets(a);
   for(i=0;a[i]!='\0';i++)
   {
      n++;
   }
   for(i=0;i<n;i++)
   {
      b[i]=a[n-i-1];
   }
   for(i=0;i<n;i++)
   {
      if(b[i]==a[i])
      {
        s++;
      }
   }
   if(s==n)
   {
      printf("\nThis is a palindrome:%s",a);
   }
   else
   {
      printf("\nThis is not a palindrome:%s",a);
   }
   return 0;
}
To download raw file Click Here

Output

Enter the string: madam
This is a palindrome

List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C


Learn All in Tamil © Designed & Developed By Tutor Joes