C program to check inputted string is palindrome or not

Palindrome – Palindrome is a sequence that can be read in the same way from both the directions; from left to right and right to left. Ex- aba, deffed etc.

Program in the C programming language to check if the inputted string is the palindrome string or not. Input a string to find if the string is palindrome. Below is the C program –


/* C program to check if the inputted string is a palindrome string or not */
#include<stdio.h>
#include<string.h>
void main()
{
     char nm[100];
     int n,i,ct=0;
     printf("Enter a string to check if it is palindrome or not \n");
     gets(nm);
     printf("String is  - \t %s \n",nm);
     
     n=strlen(nm);
     for(i=0;i<n;i++)
     {
           n--;
           if(nm[i]!=nm[n])
           {
                 ct=1;
                 break;
           }
     }
     if(ct==0)
     {
           printf(" \n Above String is a palindrome string");
     }
     else
     {
           printf(" \n Above String is not a palindrome string");
     }
     getch();
     }

Output –
Enter a string to check if it is palindrome or not – abbabba
String is – abbabba
Above string is a palindrome string

yashan has written 69 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>