Output sample Input a string: Radar It\'s a palindrome. Input another string (y/
ID: 3615375 • Letter: O
Question
Output sample
Input a string:
Radar
It's a palindrome.
Input another string (y/n)?
y
Too hot to hoot
It's a palindrome.
Input another string(y/n)?
y
Hello world
It is not a palindrome.
Input another string(y/n)?
n
#include<iostream>
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cctype>
using namespace std;
int main()
{
const int SIZE = 80;
int strlength;
char str[SIZE];
int j=0;
int front = 0, back; int flag = 1;
char again;
cout << "Input a string: ";
do
{
gets(str);
//Gets the length of string str
strlength = strlen(str);
//Convert all the characters in the string str touppercase
for( int i =0; i < strlength; i++ )
{
if(str[i])
str[i] =toupper(str[i]);
}
//Remove all the special characters except lettersa-z
for( int i=0; i < strlength; i++ )
{
if(isalpha(str[i]))
{
str[j] =str[i];
j++;
}
}
str[j] = '';
//front index is pointed to the first character in thestring str
front = 0;
//back index points to the last character in thestring str
back = j - 1;
//Compare the first characer with the lastcharacter. If they are
//the same, compare the next character.
for( int i = 0; i < (j/2) ; i++ )
{
if( str[front] != str[back] )
{
flag = 0;
break;
}
front = front + 1 ;
back = back - 1;
}
if( flag == 0 )
{
cout << "It is not apalindrome." << endl;
}
else
{
cout << "It's apalindrome." << endl;
}
cout << "Input another string(y/n)? " <<endl;
cin >> again;
}while( again == 'y' || again == 'y' );
system("pause");
return 0;
}
Explanation / Answer
please rate - thanks #include #include #include #include #include using namespace std; int main() { const int SIZE = 80; int strlength; char str[SIZE]; int j=0; int front = 0, back; int flag = 1; char again; do {coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.