palindrome is a string that reads the same both forward and backward.
C++
For example, the string "madam" is a palindrome.
Write a program that uses a recursive function to check whether a string is a palindrome.
Your program must contain a value-returning recursive function that returns true if the string is a palindrome and false otherwise. Do not use any global variables; use the appropriate parameters.
Solution.cpp
#include <iostream>//header file for input output
function
#include <cstring>//header file for string functions
using namespace std;//it tells the compiler to link std namespace
bool isPalindrome(char *inputString, int leftIndex, int
rightIndex);//function declaration
int main(){//main function
char Str[100];
cout<<"Enter a string for palindrome
check\n";
cin>> Str;//keyboard inputting
//calling
function
if(isPalindrome(Str, 0, strlen(Str) - 1)){
cout<<Str<<"
is a Palindrome \n"<< Str;
} else {
cout<<Str<<"
is not a Palindrome \n"<< Str;
}
return 0;
}
/*
* Function to check whether a string is palindrome or not
*/
bool isPalindrome(char *inputString, int leftIndex, int
rightIndex){
/* Input Validation */
if(NULL == inputString || leftIndex < 0
|| rightIndex < 0){
cout<<"Invalid Input";
return
false;
}
/* Recursion termination condition
*/
if(leftIndex >= rightIndex)
return true;
if(inputString[leftIndex] ==
inputString[rightIndex]){
return
isPalindrome(inputString, leftIndex + 1,rightIndex - 1);
}
return false;
}
output
madam
madam is a Palindrome
palindrome is a string that reads the same both forward and backward. C++ For example, the...
C++ A palindrome is a string that reads the same backward as forward. For example, the words mom, dad, madam and radar are all palindromes. Write a class Pstring that is derived from the STL string class. The Pstring class adds a member functionbool isPalindrome( )that determines whether the string is a palindrome. Include a constructor that takes an STL string object as parameter and passes it to the string base class constructor. Test your class by having a main...
A palindrome is a word that is spelled the same forward and backward. For example, rotor and redder are palindromes, but motor is not. Write a recursive function that takes a word (string) and check if it is palindrome or not (The function should return True if the word is palindrome otherwise it should return False). USING PYTHON
C++ A palindrome is a string that reads the same backward as forward. For example, the words mom, dad, madam and radar are all palindromes. Write a class Pstring that is derived from the STL string class. The Pstring class adds a member functionbool isPalindrome( )that determines whether the string is a palindrome. Include a constructor that takes an STL string object as parameter and passes it to the string base class constructor. Test your class by having a main...
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, such as madam or racecar. Write a recursive method in java that accepts a integer as its argument and returns true if it is palindrome, false otherwise. public class Recursion { public static void main(String[] args) { Recursion r = new Recursion(); System.out.println(“Is 12321 a palindrome? “+ra.isPalindrome(12321)); //true } public Boolean isPalindrome(int num){ return false;...
Palindrome Detector A palindrome is any word, phase, or sentences that reads the same forward and backward. Here are some well-know palindrome. Write a bool function that uses recursion to determine if a string arguments is a palindrome. The function should return true if the argument reads the same forward and backward. Demonstrate the function in a program
A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurses run. In this program, ask the user to input some text and print out whether or not that text is a palindrome. Create the Boolean method isPalindrome which determines if a String is a palindrome, which means it is the same forwards and backwards. It should return a boolean of whether or not it was a palindrome. Create the method reverse...
A Palindrome is a string that is spelled the same way forward and backward (example: radar). Write a Java program that asks the user to input a string and tests whether the string is a Palindrome or not. Display the message: "The string is a Palindrome" if it is, or "The string is NOT a Palindrome" if it is not. Assume that the user will enter a string without any spaces. The string can be any length. The String can...
A Palindrome is a string that is spelled the same way forward and backward (example: radar). Write a Java program that asks the user to input a string and tests whether the string is a Palindrome or not. Display the message: "The string is a Palindrome" if it is, or "The string is NOT a Palindrome" if it is not. Assume that the user will enter a string without any spaces. The string can be any length. The String can...
A palindrome is a word or phrase that reads the same forward and backward, ignoring blanks and considering uppercase and lowercase versions of the same letter to be equal. For example, the following are palindromes: • warts n straw • radar • Able was I ere I saw Elba • tacocat Write a program that will accept a sequence of characters terminated by a period and will decide whether the string—without the period—is a palindrome. You may assume that the...
A palindrome is a number or a text phrase that reads the same backward as forward. For example, each of the following six-digit integers is a palindrome: 123321, 555555, 455554, and 116611. Write a pseudocode and C++ program that reads in a six-digit integer and determines whether or not it is a palindrome. You must use the division and remainder operators. Assume input is correct (six-digit integer). Please don't use loops. Do it with only using if else.