Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please using the c++ language to solve the following question, thank you A palin

ID: 3717652 • Letter: P

Question

Please using the c++ language to solve the following question, thank you

A palindrome is a word, phrase or sequence that reads the same backward as forwards, for example, "bob", "step on no pets". Write a recursive function isPalindrome that takes a string as input and returns true if it is a palindrome, false otherwise. You might find the string:substr useful, which takes two arguments, the first being the start position of the character in the original string to be copied, the second is the length of the substring to be copied, returns the substring. For example: cout

Explanation / Answer

#include <iostream>

using namespace std;

bool isPalindrome(string s){

// if length is 0 or 1 then String is palindrome

if(s.length() == 0 || s.length() == 1)

return true;

if(s[0] == s[s.length()-1])

return isPalindrome(s.substr(1, s.length()-2));

return false;

}

int main() {

cout<<isPalindrome("madam")<< endl;

cout<<isPalindrome("fdsfsd")<< endl;

cout<<isPalindrome("surrus")<< endl;

}

Output:

1
0
1