Answer to Question #188869 in C++ for Asad

Question #188869

You know what a palindrome number is. The same concept can be used for strings. Basically, palindrome string is a string that is same if you read it forwards or backwards. Some palindrome strings examples are "dad", "radar", "madam" etc. You will have to write a program, that tells us whether the input string is palindrome or not.

Hint: Reverse the original string and compare the resultant with the original.

 


1
Expert's answer
2021-05-07T15:29:38-0400
#include <iostream>
#include <string>
using namespace std;

int main() {
    string input;

    cout << "Please enter a string: ";
    cin >> input;

    if (input == string(input.rbegin(), input.rend())) {
        cout << "Your string \'"<< input << "\' is a palindrome" << endl;
    } else {
        cout << "Your string \'"<< input << "\' is not a palindrome" << endl;
    }

    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
New on Blog
APPROVED BY CLIENTS