Question

Fix the function so that it checks if the string is a palindrome #include <iostream> using...

Fix the function so that it checks if the string is a palindrome

#include <iostream>

using namespace std;
//Fix the function so that it checks if the string is a palindrome
//(same forwards as backwards ex: racecar / radar)

bool is_palindrome(string str, int i){
//base cases
if (/* add the condition */) return false;
  
if (/* add the condition */) return true;

  
//recursive call
return is_palindrome(str, i-1);
}

int main(){
string x;
cin >> x;
  
if (is_palindrome(x,x.length())){
cout << x << " is a palindrome";
} else {
cout << x << " is not a palindrome";
}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

using namespace std;
//Fix the function so that it checks if the string is a palindrome
//(same forwards as backwards ex: racecar / radar)

bool is_palindrome(string str, int i){
//base cases
if (str[str.length()-i] != str[i-1]) return false;
  
if (i == 0 || i == 1) return true;

  
//recursive call
return is_palindrome(str, i-1);
}

int main(){
string x;
cin >> x;
  
if (is_palindrome(x,x.length())){
cout << x << " is a palindrome";
} else {
cout << x << " is not a palindrome";
}

}

_________________________

Output:

_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
Fix the function so that it checks if the string is a palindrome #include <iostream> using...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT