Question: Hello, I need help solving this Lab simulation, It uses Palindrome statements and I am very new at coding on this subject so I need
Hello, I need help solving this Lab simulation, It uses Palindrome statements and I am very new at coding on this subject so I need help solving it.
A palindrome is a word or a phrase that is the same when read both forward and backward. Examples are: "bob," "sees," or "never odd or even" (ignoring spaces). Create a program whose input is a word or phrase, and outputs whether the input is a palindrome.
If the input is bob, the output is:
bob is a palindrome If the input is bobby, the output is:
bobby is not a palindrome
Hint: Start by just handling single-word input, and submit for grading. Once passing one single-word test cases, extend the program to handle phrases. If the input is a phrase, remove or ignore spaces.
I tried to make this properly but I can't seem to get the input right for these:
If the input is never odd or even, the output is:
never odd or even is a palindrome
If the input is dr awkward, the output is:
dr awkward is a palindrome
If the input is evil is alive, the output is:
evil is alive is not a palindrome
If the input is no lemon no melon, the output is:
no lemon no melon is a palindrome
This is the incomplete code I am having problems with:
#include
#include
#include
#include
using namespace std;
int main() {
char str[20];
int i, len;
int flag = 0;
cin >> str;
len = strlen(str);
for(i=0;i
if(str[i] != str[len-i-1]){
flag = 1;
break;
}
}
if (flag) {
cout
}
else {
cout
}
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
