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

1. A palindrome is a string that reads the same front to back as it does back to

ID: 3569092 • Letter: 1

Question

1. A palindrome is a string that reads the same front to back as it does back to front. Write a function that prints out if the input C-style string is a palindrome or not. Consider
the string to be only a single word of all lower case characters. Examples of palindromes are the words - radar, mom, and racecar.
bool isPalindrome(char str[])
{


}

2. A palindrome is a string that reads the same front to back as it does back to front. Write a function that prints out if the input C-style string is a palindrome or not. Consider
the string to be only a single word of all lower case characters. Examples of palindromes are the words - radar, mom, and racecar.
void isPalindrome(char str[])
{


}

The only difference in the questions are one says bool and the other says void. Using C++ Thank you!

Explanation / Answer


bool isPalindrome(char str[])
{
   int size = strlen(str), i;
   for(i = 0; i < size / 2; i++){
       if(str[i] != str[size - i - 1]) return false;
   }
   return true;
}

void isPalindrome(char str[])
{
   int size = strlen(str), i;
   for(i = 0; i < size / 2; i++){
       if(str[i] != str[size - i - 1]){
           cout << "The string " << str << " is not a palindrome. ";
           return;
       }
   }
   cout << "The string " << str << " is a palindrome. ";
}