Answer to Question #196199 in C++ for Angel

Question #196199

Write a program using string functions that determine if the

input word is a palindrome. A palindrome word is a word

that produces the same word when it is reversed.

Sample Input/Output Dialogue:

Enter a word: CUTE

Reversed: ETUC

“Nice”

Enter a word: MAD

Reversed: DAM

“Nice”


1
Expert's answer
2021-05-20T18:20:37-0400
#include <bits/stdc++.h>
using namespace std;


bool isPalRec(char str[], int s, int e)
{
    if (s == e)
    return true;
    if (str[s] != str[e])
    return false;
    if (s < e + 1)
    return isPalRec(str, s + 1, e - 1);


    return true;
}


bool isPalindrome(char str[])
{
    int n = strlen(str);
    if (n == 0)
        return true;


    return isPalRec(str, 0, n - 1);
}


int main()
{
    char str[100];
    cout<<"Enter a string  ";
    cin.getline(str,100);


    if (isPalindrome(str))
    cout << "Yes, given string is a palindrome";
    else
    cout << "No, given string is not a palindrome";


    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