Palindrome Program in C Using String Functions

Palindrome Program in C Using String Functions. In this program, we can check the string is palindrome or not using string functions in a c programming language.

Header File String.h in C Program

The header string.h defines one variable type, one macro, and a number of functions for manipulating character arrays. 

A string is defined as a collection of characters. A character array differs from a string in that the string is terminated with the special character ‘0’. 

String declarations: A string can be declared in the same way that a one-dimensional array can.

If Else Statement in C

In C, the if-else statement is used to carry out operations based on a set of conditions. 

If and only if the given condition is true, the operations specified in the if block are executed. 

If the if (true/false expression) is false, the if/else statement adds an action to the if statement.

The program will always execute something with an if/else statement because it will either execute the true code block or the false code block.

Palindrome Program in C Using String Functions

#include<stdio.h> 
#include<string.h>
int main()
{
char s[500]; 
int i,n,c=0;
printf("Enter The String ");
gets(s);
n=strlen(s);
for(i=0;i<n/2;i++) 
{
if(s[i]==s[n-i-1])
c++;
}
if(c==i)
printf("String is Palindrome");
else
printf("String is Not Palindrome");
return 0;
}

Output:

Enter The String maam
String is Palindrome