C++ program : To find the given string or number is parlindrom or not




#include<iostream.h>
#include<conio.h>
#define size 50

class numchar
{
   int len;
   public:
   char s[size];
   int parlindrom();
};
int numchar::parlindrom()
{
   for(len=0;s[len]!='\0';len++);
   int i,j;
   for(i=0,j=len-1;i<len;i++,j--)
      if(s[i]!=s[j])
         return 0;
   return 1;
}

int main()
{
   clrscr();
   numchar x;
   cout<<"Enter the String or number :";
   cin>>x.s;
   if(x.parlindrom())
      cout<<"\tis parlindrom";
   else
      cout<<"\tis not parlindrom";
   getch();
   return 0;
}


Class diagram 

(click image to view large)

 

 


Related Posts:

0 comments:

Post a Comment