Wednesday, May 23, 2018

PROGRAM TO CHECK WHETHER A TEXT IS PALINDROME OR NOT IN C++

#include<iostream.h>
#include<conio.h>
#include<string.h>
class Palindrome
{
 public:
 char str[20];
 int len,i,p;
 Palindrome()
 {
  p=0;
 }
 void input()
 {
  cout<<"Enter the text"<<endl;
  cin>>str;
  len=strlen(str);
 }
 void work()
 {
  for(i=0;str[i]!='\0';i++)
  {
   if(str[i]==str[len-1-i])
    p++;
  }
 }
 void show()
 {
  if(p==len)
   cout<<"Palindrome";
  else
   cout<<"Not";
 }
};
void main()
{
 Palindrome ob;
 clrscr();
 ob.input();
 ob.work();
 ob.show();
 getch();
}

                                                   OUTPUT


No comments:

Post a Comment