C Program to Check String is Palindrome or Not

C Program to Check String is Palindrome or Not

Write C Program to Check String is Palindrome or Not

// C Program to Check String is Palindrome or Not

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

int main()
{
	char S1[100] = "NAINA", S2[100];

	strcpy(S2, S1);

	int i = 0, temp;
	int n = strlen(S1);

	while(i < n/2)
	{
		temp = S1[i];
		S1[i] = S1[n-i-1];
		S1[n-i-1] = temp;
		i++;
	}

	printf("String :--> %s", S2);
	if(strcmp(S2,S1)!=0)
	{
		printf("\nString is not Palindrome");
	}
	else
	{
		printf("\nString is palindrome");
	}
	return 0;
}

Output:

Run 1:
String :--> NAYAN
String is palindrome

Run 2:
String :--> NAINA
String is not Palindrome