C Program to Check Given String is Palindrome or Not

C Program to Check Given String is Palindrome or Not

Write a Program to Check Given String is Palindrome or Not

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

#include <stdio.h>
#include <string.h>

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

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

}

int main()
{
	char S[50];

	printf("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