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.
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; }
Comments
Leave a comment