C++ Program to Check Given String is Palindrome or Not

Write C++ Program to Check Given String is Palindrome or Not

// CPP Program to Check Given String is Palindrome or Not

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

using namespace std;

void palindrome(char S[], int i)
{
    int l = strlen(S) - (i + 1);

    if(S[i] == S[l])
    {
        if( i + 1 == l || i == l)
        {
            cout << "\nString is Palindrome";
            return;
        }
        palindrome(S, i + 1);
    }
    else
    {
        cout << "\nString is not Palindrome";
    }

}

int main()
{
	char S[50];

	cout << "Enter String :--> ";
        gets(S);

        palindrome(S, 0);
	return 0;
}

Output:

Run 1:
Enter String :--> nayan

String is Palindrome

Run 2:
Enter String :--> Codecrucks

String is not Palindrome

≪ Previous | Next ≫