C++ Program to check whether a String is Palindrome or not

C++ Program to check whether a String is Palindrome or not

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();
int i,j,len,flag=1;
char a[20];
cout<<“Enter a string:”;
cin>>a;

for(len=0;a[len]!=’’;++len);
for(i=0,j=len-1;i<len/2;++i,–j)
{
if(a[j]!=a[i])
flag=0;
}

if(flag==1)
cout<<“nThe string is Palindrome”;
else
cout<<“nThe string is not Palindrome”;
getch();
}

14 thoughts on “C++ Program to check whether a String is Palindrome or not

    1. Neeraj Mishra

      A string is palindrome if first half is equal to second half. Therefor the 2nd loop run till half of the length of string.

      Reply
  1. kiruthinesan

    for(len=0;a[len]!=’’;++len);
    ” this symbol i could not understand.

    Reply
    1. Talha

      This if for getting the length of appropriate array. after writing a word or a paragraph the length is pointing at a final index. which is the length of an array.

      Reply
  2. Tamrat

    How can I write a c++ program that print the ff…
    5
    4 5 4
    3 4 5 4 3
    2 3 4 5 4 3 2
    1 2 3 4 5 4 3 2 1
    please help me…
    Thanks!

    Reply
    1. Durgesh

      #include

      int main()
      {
      int i,j,k;
      for(i = 5; i >= 1; i–)
      {

      for(j = i; j<5; j++)
      {
      std::cout <=i; k–)
      {
      std::cout << k;

      }
      std::cout<<std::endl;
      }
      return 0;
      }

      Reply
      1. Tamrat

        Thanks for the reply.
        I wonder if you see it and reply again.

        Reply
      2. Tamrat

        But, It is somehow tricky if the output is

        5
        4 5 4
        3 4 5 4 3
        2 3 4 5 4 3 2
        1 2 3 4 5 4 3 2 1

        I wonder if you do it in c++.
        Thanks anyways.

        Reply

Leave a Reply

Your email address will not be published. Required fields are marked *