1. A Palindrome is a word that is the same backwards as it is forwards. For example, the words kayak and madam are Palindromes.
a. Request an 5 character value from the console.
b. If the input string is not 5 characters, print that the word is not a 5 character word and exit.
c. If the input string is 5 characters, determine if the word is or is not a Palindrome. Hint: String indexes can be used to compare letter values.
d. If the word is a Palindrome, print that it is a Palindrome. if not, print that it is not.
If you can use loops then do the problem for any number of characters.
Output Example (input is bold and italicized)
Enter an odd letter word: test
test is not an odd word.
Output Example (input is bold and italicized)
Enter an odd word: kayak
kayak is a palindrome.
Language C++
CODE
#include <iostream>
using namespace std;
int main() {
string one;
cout << "Enter an odd word: ";
cin >> one;
if(one.length() % 2 == 0)
cout << one << " is not an odd word.";
else
{
int out = 1, last = one.length() - 1;
for(int first=0; first < last; first++, last--)
{
if(one[first] != one[last])
{
out = 0;
cout << one << " is not a palindrome";
break;
}
}
if(out == 1)
cout << one << " is a palindrome";
}
}
OUTPUT
Enter an odd word: kayak
kayak is a palindrome
PLEASE UP VOTE
Get Answers For Free
Most questions answered within 1 hours.