# Question & Answer: Write a recursive function named isPalindrome that takes a C++ string as a parameter and returns a bool indicating…..

Write a recursive function named isPalindrome that takes a C++ string as a parameter and returns a bool indicating whether that string is exactly the same forwards and backwards. For example, “racecar” would return true, but “Racecar” would return false. The file must be named: isPalindrome.cpp.

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: Write a recursive function named isPalindrome that takes a C++ string as a parameter and returns a bool indicating…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS \$13/PAGE

#include <iostream>
#include <string.h>
using namespace std;
bool chkpallen(char[]);
bool pallen(char[],int ,int);
int main()
{
if (chkpallen(name))
cout<<“it is pallendrome”<<endl;
else
cout<<“it is not pallendrome”<<endl;

return 0;
}
bool chkpallen(char name[])
{
int len=strlen(name);
if (len==0)
return true;
return pallen(name,0,len-1);
}
bool pallen(char name[], int a, int b)
{
if (a==b)
return true;
if (name[a]!=name[b])
return false;
if (a<b+1)
return pallen(name,a+1,b-1);
return true;
}

output:screenshot:

output when it is not pallendrome string:
#include <iostream>
#include <string.h>
using namespace std;
bool chkpallen(char[]);
bool pallen(char[],int ,int);
int main()
{
char name[]=”racecars”;
if (chkpallen(name))
cout<<“it is pallendrome”<<endl;
else
cout<<“it is not pallendrome”<<endl;
return 0;
}
bool chkpallen(char name[])
{
int len=strlen(name);
if (len==0)
return true;
return pallen(name,0,len-1);
}
bool pallen(char name[], int a, int b)
{
if (a==b)
return true;
if (name[a]!=name[b])
return false;
if (a<b+1)
return pallen(name,a+1,b-1);
return true;
}