Google Add


Program to Check whether String is Palindrome or not in C, C++

Write a C, C++ program to check whether string is palindrome or not. 

In this program we are using in-built string functions.

 Program to check whether string is palindrome or not without using any in-built library function.

Program to check whether number is palindrome or not

Programming questions on strings.

Let's first understand what is Palindrome.

Palindrome is a word, phrase, or sequence that reads the same backwards as forwards.

For example - Nitin, Madam etc.

If you reverse word Nitin it's still remains the same.

How do we check whether a string is palindrome or not ?

We have discussed, what is palindrome so how do we check whether input string is palindrome or not. 

There are multiple approaches, let's discuss it.

METHOD 1  Take input string then reverse the input string if both strings are same then it's a palindrome.

METHOD 2 Traverse string from both the ends and compare, if both the indexes are equal then it's a palindrome. 

Implementation of method 2 to check whether string is palindrome or not.

Program to Check Whether a String is Palindrome in C


Void main()

   /* Declare String. 
      String is a series of characters.

   char str1[150], str2[150];  

   /* Take input string. */

   printf("Enter any string");

  /* Copy the value of str1 into str2. */

   /* Reverse string 2. */

   if( strcmp(str1,str2) == 0 )
      printf("Not a pailndrome.\n");


Program to check whether string is palindrom in C++


No comments:

Post a Comment