Monday, May 24, 2010

Wat is the C program to display all the palindromes in a given string??

Eg: the word "dadmom" has 2 palindromes..and we should display them

Wat is the C program to display all the palindromes in a given string??
Nested for loops would do it.
Reply:#include%26lt;stdio.h%26gt;


#include%26lt;string.h%26gt;


void main()


{


char word[80];


int i,j,len,flag=0;


printf("enter a string:");


scanf("%s",%26amp;word);


len=strlen(word);


for(i=0,j=len-1;i%26lt;=len/2;i++,j--)


{


if(word[i]==word[j])


flag=1;


else


flag=0;


}


if(flag==1)


printf("given string is palindrome:%s",word);


else


printf("given stringis not apalindrome:%s",word);


}








Output:





Enter a string:


Madam


Given string is palindrome.


No comments:

Post a Comment