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;
}
Step-by-step explanation: