C program to find given string is palindrome or not

A string is said to be a palindrome if the given string is same when it is reversed. This can be explained clearly with the help of an example
Example:

Input: mom
output : Palindrome

Here the given string is 'mom', this string when it is reversed we get the same string as an output that is 'mom' such type of strings are said to be palindrome string

Input: 'program'
Output: Not palindrome

The source code for the above example is written below:

Program:

#include <stdio.h>
#include <conio.h>
int main()
{
char f[20], s[20];
int i;   //declaration
clrscr();  //clear screen
puts("Enter any string: ");  //display on screen
gets(f);  //accepts the input ans store in 'f'
strcpy(s, f);  //copies string in f to s
strrev(s);    //reverse the string
i = strcmp(f,s)  //compare the strings
if(i == 0)
printf("\nThe given string is a palindrome");
else
printf("\nThe given string is not a palindrome");
return 0;
}

Output:

Enter any string: MOM
The given string is a palindrome

Post a Comment

0 Comments