Q:

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

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

int main()
{
   
    cout<<"=====================================";
    cout<<"\nVisit - www.nerdutella.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:

=====================================

Visit - www.nerdutella.com

=====================================

Enter a String: MaDaM

MaDaM==> Is Palindrome 

Enter a String: 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Program to Find The Length of a String Without... >>
<< C++ Program To Print A String...