Answer to Question #25041 in C++ for hanrik

Question #25041
Write a C++ program that accepts string and returns true if it is a palindrome. A string is a palindrome if it can be read forward and backward with the same meaning.
1
Expert's answer
2013-02-26T09:59:53-0500

#include <iostream>
#include <fstream>
#include <cstring>


using namespace std;

int main(void){
char word[81];
do{
bool palindrome=true;


cout << "Please enter a word" << endl;
cin>>word;
int length = strlen(word);
for (int i=0; i<length; i++){
word[i] = toupper(word[i]);
}
int(length/2);
if (length>0){
for(int i=0;i<(length);i++)
{
if(word[i]!=word[length-1-i])
palindrome=false;
}
}
if(palindrome==true)
{
cout << "The word is a palindrome" << endl;
}
else
{
cout << "The word is not a palindrome" << endl;
}

} while (word!="END");

return(0) ;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS