Write a recursive function checkPalindrome that checks if a

Write a recursive function checkPalindrome() that checks if a given string made of only letters and numbers is a palindrome.

Solution

#include <iostream>
#include<cstring>
using namespace std;


bool isPalin(int start, int end, string &str)
{
if (start >= end) // all characters in string are checked
return true;
if (toupper(str[start]) != toupper(str[end])) //compare 1st character with last,2nd with second last and so on after capitalizing
return false;
return isPalin(++start, --end, str); // increment start index and decrement end index
}
int main()
{
string str;
int length;
cout<<\"Enter the String to check:\";
cin>>str;
length = str.length();
if(isPalin(0,length-1,str))
cout<<\"\ \"<<str<<\" is a palindrome\";
else
cout<<\"\ \"<<str<<\" is not a palindrome\";
   return 0;
}

output:

 Write a recursive function checkPalindrome() that checks if a given string made of only letters and numbers is a palindrome.Solution#include <iostream> #

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site