09/11/2015

C++ Program to Check Whether Given String is a Palindrome

Problem:- Write A C++ Program To Check String Is Palindrome Or Not or C++ Program to Check Whether Given String is a Palindrome or Check Given String is Palindrome or not in C++ or C++ Program to Check String is Palindrome or not or Program to check a string is palindrome or not or C++ Program to Check Whether String is Palindrome or C++ program to check whether given string is palindrome or not? or C++ Program to Check whether a string is A Palindrome or Not or C++ Program to Check Number is Palindrome or Not or C Program to Check if a Given String is A Palindrome.

Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.

Logic:- What Is Palindrome?

"a word, phrase, or sequence that reads the same backward as forwards"

" Matlab Ulta Seedha Ek Saman " or " मतलब उल्टा सीधा एक समान "

Simple if the string is "MADAM" compare the First letter index of 'M' to the last letter index of 'M' and again compare to 2nd letter index to the second last letter index if both are same then continue for next upcoming letters and repeat the same process continue to repeat if all Word's are same then String Is Palindrome.

Also Check:- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard in C++.

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post or if you have any Query you can ask there with lots of coders also suggest to your Friends to join and like our page.

Try to Solve- Try to solve this problem for Numbers, Check weather number is Palindrome.

Solution:-


#include<iostream>
#include<string.h>
using namespace std;

int main()
{
/*Visit - www.programmingwithbasics.com*/
   
    cout<<"=====================================";
    cout<<"\nVisit - www.programmingwithbasics.com";
    cout<<"\n=====================================";
    
    while(1)
    {
    char string1[20];
    int i, length;
    int flag = 0;
    cout << "\n\nEnter a String: ";
    cin >> string1;
    length = strlen(string1);
    for(i=0;i < length ;i++)
  {
        if(string1[i] != string1[length-i-1])
  {
            flag = 1;
            break;
      }
  }
  cout<<"\n\n";
    if (flag) 
  {
        cout << string1 << "==> Is Not Palindrome " << endl;
    }  
    else 
{
        cout << string1 << "==> Is Palindrome " << endl;
    }
}
    return 0;
}

Output:-

C++ Program to Check Whether Given String is a Palindrome

You May Also See


1. C Program For Find The Gross Salary Of An Employee

2. C Program For Calculate Percentage Of 5 Subjects

3. C Program For Converting Temperature Celsius Into Fahrenheit

4. C++ Program To Find Character Is Vowel Or Not

5. C++ Program To Calculate Factorial Of A Given Number

6. C++ Program To Read Integer (N) And Print First Three Powers (N^1, N^2, N^3)

7. C++ Program To Swap Two Number Without Using Third Variable




Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: