A palindrome is a word or a phrase that is the same when read both forward and backward. Examples are: "bob," "sees," or "never odd or even" (ignoring spaces). Write a program whose input is a word or phrase, and that outputs whether the input is a palindrome.
Ex: If the input is:
bob
the output is:
bob is a palindrome
Ex: If the input is:
bobby
the output is:
bobby is not a palindrome
IN C++ PLEASE!
#include <iostream> #include <string> #include <cctype> using namespace std; int main() { string data, reversed, modified; char ch; getline(cin, data); for (int i = 0; i < data.size(); ++i) { ch = tolower(data[i]); if (isalnum(ch)) { modified += ch; reversed = ch + reversed; } } if (reversed == modified) cout << data << " is a palindrome" << endl; else cout << data << " is not a palindrome" << endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.