1.   Write a program using string functions that determine if the input word is a palindrome. A palindrome word is a word that produces the same word when it is reversed.
#include <string>
#include <algorithm>
#include <cctype> Â
#include <iostream>
using namespace std;
int main()
{
   string str,strTest;
   int i=0,j=0;
   cout<<"Enter a word: ";
   getline(cin, str);
   int len= str.length();  // len = length of input string
  Â
    for(i=0;i<len;i++)
       if(str[i]!=' ')       // overwrite all but spaces
          strTest.push_back(toupper(str[i])); // in upper case
    Â
 // Test whether the elements in two ranges are equal
   if (equal(strTest.begin(), strTest.begin() + strTest.size() / 2, strTest.rbegin()))
      cout << "It is a Palindrome!";
   else
      cout << "a";
   cout << endl << endl;
   system("PAUSE");
   return 0;
}
Comments
Leave a comment