Friday, 22 June 2012

write a c program to read a string and check whether string is palindrome or not(using staic implementation of stack)


/*write a c program to read a string and check whether string is
palindrome or not(using staic implementation of stack)
*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i,len,top,flag=0;
char str[50],s[50];
clrscr();
printf("\nenter the string:-");
gets(str);
len=strlen(str);
printf("\nthe length of string is :-%d",len);
for(top=0;top<len;top++)
{
s[top]=str[top];
}
top--;
printf("\nthe reverse string is:-");
for(i=top;i>=0;i--)
{
printf("%c",s[i]);
}
i=0;
while(top>=0)
{
if(str[i]==s[top])
flag=1;
else
break;
i++;
top--;
}
top++;
if(flag==1&&top==0)
printf("\nthe string is palindrome");
else
printf("\nthe string is not palindrome");
getch();
}
/*
enter the string:-peer                                                        
                                                                               
the length of string is :-4                                                    
the reverse string is:-reep                                                    
the string is not palindrome


enter the string:-pop                                                          
                                                                               
the length of string is :-3                                                    
the reverse string is:-pop                                                    
the string is palindrome                                                      
      */

No comments: