Friday, November 23, 2012

WRITE A C PROGRAM TO FIND IF THE GIVEN STRING IS A PALLINDROME


/* WRITE A C PROGRAM TO FIND IF THE GIVEN STRING IS A 
    PALLINDROME */

#include<stdio.h>
#include<conio.h>

#define MAX 30

void main()
{
            char str[MAX],*fr,*re,flag=0;
            int len;
            clrscr();
            printf("Enter a String : ");
            gets(str);
            for(len=0;str[len]!='\0';len++);
            fr=str;                             /* same as fr=&str[0];*/
            re=&(str[len-1]);  /* re is pointing to last element */
            while(fr < re)
            {
                        if((*fr)!=(*re))
                                    flag=1;
                        fr++,re--;
            }
            if(!flag)
                        printf("The \"%s\" is a pallindrome",str);
            else
                        printf("The \"%s\" is a not a pallindrome",str);
                        getch();

}



/*
            =====OUT PUT=====

      1.Enter a String : BHARATH
            The "BHARATH" is a not a pallindrome

      2.Enter a String : LIRIL
            The "LIRIL" is a pallindrome

      3.Enter a String : 12321
            The "12321" is a pallindrome

*/

0 comments:

Post a Comment