64 638
Assignments Done
99,2%
Successfully Done
In September 2018

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.
Expert's answer

#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions