Q. 96. Write a C++ program to input a Word and check if it is a Palindrome (eg: madam, civic, kayak).
Note: Ignore case sensitiveness (eg: madam or Madam are both Palindrome)
Copy Code:
#include <iostream>
#include <cctype>
using namespace std;
int main()
{
  int i = 0, len = 0; char ch [50];
  cout << "Enter a Word : ";
  cin >> ch ;
  while (ch [ i ] != '\0')
   {
      len+=1;  i+=1;
    }
  for ( i=0 ; i <= len/2 ; ++i )
  {
     if ( toupper(ch[ i ]) != toupper(ch[ len - i - 1]))
        {
            cout << ch << " is Not a Palindrome";
            goto e; 
        }    
   }
  cout << "GREAT !!! " << ch << " is a PALINDROME";
  e:   
  return 0;
}

 
No comments:
Post a Comment