Tuesday 26 January 2016

Write a C program to check if the given string is a palindrome or not using string functions - Online Rockers

Post by On at 19:13:00
                     Hi viewers , today are going to look at string palindrome .

What is string palindrome?


               Just consider a word , say hello . When you reverse it you get olleh . The initial word and the reversed word or not the same. When you reverse the word Malayalam , you get the same word . This is called string palindrome.


                 Let's write a C program to find if the string accepted from the user is a palindrome or not . To compile this you need a C compiler If you don't have a compiler get it from here.





Source code:


#include<stdio.h>
#include<string.h>
int main()
{
char str[100],rev[100];                                  //declare strings
printf("Enter the string");
gets(str);                                                       // accept string str from user
strcpy(rev,str);                                             // copying string from str to rev
strrev(rev);                                                  //reverse the string rev
if((strcmp(rev,str))==0)                             //if else condition to check str and rev are same
{
printf("\nThe given string is a palindrome");
}
else
{
printf("\nThe given string is not a palindrome");
}
return 0;
}



Output:


Sample output 1:


C program String palindrome first output                                                                                         

Sample output 2:                                                                                             



C program String palindrome second output



                Hope you would have understood the concept of string palindrome.

Check out other C programs:

We value your suggestions and feedback.

Subscribe to our blog to get posts by mail.

Fill out the subscription form on our page.

Share it with your friends in social media

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...