Social Icons

Tuesday, 18 February 2014

Program to check whether given string is palindrome or not

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int i,j,len,f=1;
char s[20];
cout<<"\n Enter a string : ";
cin>>s;

for(len=0;s[len]!='\0';++len);
for(i=0,j=len-1;i<len/2;++i,--j)
{
if(s[j]!=s[i])
f=0;
}

if(f==1)
cout<<"\n\tThe string is Palindrome";
else
cout<<"\n\tThe string is not Palindrome";
getch();
}


                                                        Output

No comments:

Post a Comment