In: Computer Science
This question has been answered before. I need a new, slightly modified code for the following:
A palindrome is a word that it reads the same left to right and right to left. For this programming assignment, you need to write a C++ program that does the following:
Please provide new code along with screenshot of output.
code:
#include <bits/stdc++.h>
using namespace std;
bool checkingPalin(char str[],int s,int e){ //checking
function
if (s==e)
return true;
if (str[s]!=str[e]) //checking first and last
charecters
return false;
if (s<e+1) //checking middle charecter
return checkingPalin(str,s+1,e-1); //calling by itself
function
return true;
}
bool isPalindrome(char s[]){ //Palindrome function
int n = strlen(s); //initiazing the variable with
string length
if (n == 0)
return true;
return checkingPalin(s,0,n-1); //returing the checking
function
}
int main(){
char s[40];
cin>>s; //taking string from the user
if (isPalindrome(s)) //calling function
cout<<"Given string is Palindrome";
else
cout<<"Given string is not a Palindrome";
}