Tuesday 17 March 2015

To check the given string is palindrome or not Using C


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

void main()
{
char str[20], rev[20] ;
int i, j, l ;
clrscr() ;
printf("Enter a string : ") ;
scanf("%s", str) ;
for(l = 0 ; str[l] != '\0' ; l++) ;
for(i = l - 1, j = 0 ; i >= 0 ; i--, j++)
rev[j] = str[i] ;
rev[j] = '\0' ;
if(stricmp(str, rev) == 0)
printf("\nThe given string is a palindrome") ;
else
printf("\nThe given string is not a palindrome") ;
getch() ;
}

RUN 1 :
~~~~~~~
Enter a string : madam
The given string is a palindrome
RUN 2 :
~~~~~~~
Enter a string : malayalam
The given string is a palindrome
RUN 3 :
~~~~~~~
Enter a string : liril
The given string is a palindrome
RUN 4 :
~~~~~~~
Enter a string : bhuvan
The given string is not a palindrome

No comments:

Post a Comment