Write a function that checks whether a given string is Palindrome or not. Use this Function to find whether the string entered by user is Palindrome or not.
#include<iostream.h>
#include<conio.h>
#include<string.h>
class palindrome
{
char w[];
public:
void palin(char w[]);
};
void palindrome:: palin(char r[])
{
char *q;
int count=0;
int a=strlen(r);
q=new char[a-1];
for(int
i=strlen(r)-1;i>=0;i--)
{
q[count]=r[i];
count++;
}
cout<<"the reversed word is
"<<q<<" hence
"<<endl;
if(strcmp(q,r)==0)
cout<<"palindrome word";
else
cout<<"not a palindrome word";
delete[] q;
}
void main()
{
clrscr();
char r[100];
cout<<"enter the string which has to be
checked whether it is palindrome or not"<<endl;
cin.getline(r,100);
palindrome obj;
obj.palin(r);
getch();
}
Comments
Post a Comment