create a program in c++ to determine whether any 5-letter word is a palindrome. Palindromes are words or sentences that read the same backward or forward. For example, “kayak” is a palindrome while “meter” is not. Ask the user to input 5 characters. You will need five separate variables to store these five characters. After obtaining the characters, compare the characters to determine if the word is a palindrome and output an appropriate message. Ex: Please enter 5 letters: h a p p y output: happy is NOT a palindrome word!
Please enter 5 letters: r a d a r output: radar is a palindrome word!
C++ code:
#include <iostream>
using namespace std;
int main(){
//initializing all 5 letters
char c1,c2,c3,c4,c5;
//asking for them
cout<<"Please enter 5 letters: ";
//accepting them
cin>>c1>>c2>>c3>>c4>>c5;
//checking if first and last and 2nd and 4rth are same
if(c1==c5 && c2==c4)
//printing palindrome
cout<<c1<<c2<<c3<<c4<<c5<<" is
a palindrome word!"<<endl;
else
//printing not palindrome
cout<<c1<<c2<<c3<<c4<<c5<<" is
NOT a palindrome word!"<<endl;
return 0;
}
Screenshot:
Input and Output:
Get Answers For Free
Most questions answered within 1 hours.