C program to check whether a given string is palindrome or not

This program will implement the string functions like strrev(), strcmp() for its operation. The program will deploy two string variables and an integer variable. Firstly, the program will copy the value of the string entered by the user to another string variable. Then the program will use the function strrev() to compute the reverse of the string in the second variable. So, the first variable will contain the entered string and the second variable will contain the reverse of the same string. Later, the program implements strcmp() to compare the strings of those two variables. The output will be displayed on the basis of the result inferred by these operations.

Before moving onto the code you need to make sure that you know the basic concepts of the following topics.

Code:

#include<stdio.h>
#include<string.h>
int main()
{
	int i;
	char s1[50], s2[50];
	puts("Enter a string: ");
	gets(s1);
	strcpy(s2, s1);
	strrev(s2);
	i=strcmp(s1, s2);
	if(i == 0)
	puts("The string is in palindrome");
	else
	puts("The string is not in palindrome");
	}

This code will display the output as below.

Output:

Enter a string:
exe
The string is in palindrome
SHARE C program to check whether a given string is palindrome or not

You may also like...

Leave a Reply

Your email address will not be published.

Share