Ads 468x60px

Saturday 10 December 2011

C++ program to check if the string is palindrome or not

This is a simple C++ program that accepts string from user and check it whether it is a palindrome or not. Below is the source code of the program :

// Program to check whether the string is palindrome or not.
#include 
#include 
#include 
void main()
{
 char str[20];
 int i, j;
 cout << "\n\t";
 cout << "\n\tEnter the string ";
 cin >> str;  // To read the string
 char flag = 'y';
 cout << "\n\tThe entered string is ";
 for (i = 0; str[i] != '\0'; i++)
  cout << str[i];
 for (j = 0, i -= 1; i>j; j++, i--)
 {
  if (str[i] != str[j]) // Checking for palindrome
  {
   flag = 'n';
   break;
  }
 }
 if (flag == 'n')
  cout << " is not palindrome ";
 else
  cout << " is a palindrome";
 getch();
}

Sourcewww.LearnCandCpp.com

For any query, post it as a comment below.

1 comment:

Unknown said...

Below is the source code of the program :
dissertation-topics-examples.info

Post a Comment