Skip to content

Commit

Permalink
Create Checking_palindrome_using_Recursion.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
roughking07 committed Oct 2, 2022
1 parent 8e16d97 commit d3e6acb
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Recursion/Checking_palindrome_using_Recursion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <iostream>
#include<string>
using namespace std;

bool isPalindrome(string &str,int start,int end)
{
if(start >= end) //base case
return true;
//if mismatch happens false will be returned else true
return ((str[start] == str[end]) && isPalindrome(str,start+1,end-1));

}

int main()
{
string str;
cin>>str;
int length = str.length();
bool ans = isPalindrome(str,0,length-1);
if(ans == true)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
return 0;
}

0 comments on commit d3e6acb

Please sign in to comment.