"Check a String is Pallindrome or Not" using Recursion

This program is to check whether a string is pallindrome or not using Recursion in C++.

Example: Input: "malayalam"
                Output: Yes




#include <iostream>
#include<string.h>

using namespace std;
int isPallindrome(char A[],int j,int i)
{
    if(A[j]!=A[i])
    {
        return 0;
    }
    if(i==j)
    {
        return 1;
    }
    int ans=isPallindrome(A,j-1,i+1);
    return ans;
}

int main()
{
    int i;
    char A[50];
    cin.getline(A,50);
    int j=strlen(A);
    int y=isPallindrome(A,j-1,0);
    if(y==0)
    {
        cout<<"false"<<endl;
    }else
    if(y==1)
    {
        cout<<"true"<<endl;
    }

}

Comments

Popular posts from this blog