Ask Question
18 January, 06:52

5.11 LAB: Palindrome A palindrome is a word or a phrase that is the same when read both forward and backward. Examples are: "bob," "sees," or "never odd or even" (ignoring spaces). Write a program whose input is a word or phrase, and that outputs whether the input is a palindrome.

+4
Answers (1)
  1. 18 January, 10:12
    0
    The following are the program in the C+ + Programming Language.

    / / set the header file

    #include

    #include

    //set the namespace

    using namespace std;

    //declare boolean type function

    bool Palindrome (string s)

    {

    //set the for loop

    for (int i = 0; i < s. length (); + +i)

    {

    //check that s[i] is not equal to length

    if (s[i]! = s[s. length () - i - 1])

    {

    //then, return false

    return false;

    }

    }

    return true;

    }

    //declare the main function

    int main ()

    {

    //declare string type variable

    string st;

    //get string type input in that variable

    getline (cin, st);

    //check the following function is returns true

    if (Palindrome (st))

    {

    //then, return the following result with message

    cout << st << " is a palindrome" << endl;

    }

    //otherwise

    else

    {

    //return the following result with message

    cout << st << " is not a palindrome" << endl;

    }

    return 0;

    }

    Output:

    bob

    bob is a palindrome

    Explanation:

    The following are the description of the program.

    Set the required header files and namespace then, declare function 'Palindrome () ' and pass the string type argument 's' in its parameter. Then, set the for loop statement that iterates from 0 and end at the length of the string, set the if conditional statement that checks the s[i] is not equal to its length, then it returns false otherwise returns true. Finally, declare the main function in which we set the string data type variable 'st' and get the string data type input from the user in it. Then, set the if conditional statement that checks the following function returns true or false.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “5.11 LAB: Palindrome A palindrome is a word or a phrase that is the same when read both forward and backward. Examples are: "bob," "sees," ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers