The is_palindrome function checks if a string is a palindrome. A palindrome is a string that can be equally read from left to right or right to left, omitting blank spaces, and ignoring capitalization. Examples of palindromes are words like kayak and radar, and phrases like "Never Odd or Even". Fill in the blanks in this function to return True if the passed string is a palindrome, False if not.

Respuesta :

Answer:

#include <iostream>  

using namespace std;  

   

// To check String is palindrome or not  

bool Palindrome(string str)  

{  

   int l = 0, lenght = str.length();  

   

   // Lowercase string  

   for (int i = 0; i < lenght; i++)  

       str[i] = tolower(str[i]);  

   

   // Compares character until they are equal  

   while (l <= lenght) {  

   

       if (!(str[l] >= 'a' && str[l] <= 'z'))  

           l++;  

   

       else if (!(str[lenght] >= 'a' && str[lenght] <= 'z'))  

           lenght--;  

   

       else if (str[l] == str[lenght])  

           l++, lenght--;  

   

       // If characters are not equal(not palindrome ) then return false

       

       else

           return false;  

   }  

   

   // Returns true if sentence is equal (palindrome)  

   return true;  

}  

   

int main()  

{  

   string sentence;  

   getline(cin, sentence) ;  

   if (Palindrome(sentence))  

       cout << "Sentence is palindrome.";  

   else

       cout << "Sentence is not palindrome.";  

   

   return 0;  

}  

Explanation: