C Program to Check String Is Palindrome or Not

A palindrome is a string that reads the same regardless of whether it is in forwards or backwards order. For example, the word radar is a palindrome because it reads the same way forwards and backwards.

Let's write a C program to check string is palindrome or not.

C Program to Check String Is Palindrome or Not

Let's create a file named palendrome.c and add the following source code to it.
#include<stdio.h>   
# include<string.h> 

void main()
{
	char str[80],rev[80];
	int n,i,x;
	printf("Enter a string: ");
	scanf("%s",str);
	n=strlen(str);
	x=0; 
	for(i=n-1;i >=0;  i--)
	{
		rev[x]=str[i];
		x++;
	}
	rev[x]='\0';
	if(strcmp(str,rev)==0)
		printf("The %s is palendrome",str);
	else
		printf("The %s is not palendrome",str);
}

To compile and run the above C program, you can use C Programs Compiler Online tool.

Output:

Enter a string: radar
The radar is palendrome


Comments