write a C++ program code to check whether the word is palindrome or not.A palind
ID: 671769 • Letter: W
Question
write a C++ program code to check whether the word is palindrome or not.A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward.write a program that uses a recursive function to determine if a string is acharacter-unit palindrome.Function returns a boolean value. Function uses call by value with a single string parameter. Ask the user for a word. Output the input along with whether it "is a palindrome" or "is NOT a palindrome". Allow the user to decide whether to do another or exit the program.
Explanation / Answer
#include <iostream>
#include <string.h>
#include <stdlib.h>
using namespace std;
bool palindrome(char input[50],int start, int end)
{
if(start >= end )
{
return 1;
}
else if(input[start] == input[end])
{
return palindrome(input, start+1,end-1);
}
else
return false;
}
int main()
{
char input[50],choice;
bool flag;
int len;
while(1)
{
cout<<"Enter the string: ";
cin>>input;
len = strlen(input);
flag = palindrome(input, 0, len-1);
if(flag == 1)
cout<<input<<" is a palindrome."<<endl;
else
cout<<input<<" is not a palindrome."<<endl;
cout<<"Do you want to check with another string: (Y)es or (N)o: ";
cin>>choice;
if(choice == 'N')
exit(0);
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.