Sunday, 16 February 2014

Source code in c++ using header file iostream.h, stdlib.h, string.h and conio.h




When a string is madeup by those characters, when we read them from left hand side, or we read from right hand side the String will remain the same then it is called a Palindrome like the word "MADAM". (in hindi "Ulta Sidha Ek Saman") Here this program tells us whether the given integer number is a type of Palindrome or not. To know more logic to it, please see the video attached with this.
// A Source code of  C++  program to check the Name or String is a Palindrome or not.
#include<iostream.h> // to use cin>> and cout<< as input and output
#include<stdlib.h>    //to include the function itoa() which convert an integer to string
#include<conio.h>   //to use the functions clrscr() and getch() written inside
#include<string.h>  //to use the function named strlen() designed inside it


void main()
 { int num, left, right;
   char strnum[10],flag='y';


   clrscr();
   cout<<"\n Please enter the integer number only"; cin>>num;

   itoa(num, strnum, 10);
   cout<<strnum;

   left=0;
   right=strlen(strnum)-1;
   while((flag=='y')&&(left<=right))
    {
      if(strnum[left]==strnum[right])
{left++; right--;}
      else
flag='n';
    }
   if(flag=='n')
     cout<<"\n The given number is NOT a Palindrome";
   else
     cout<<"\n The given number is a  Palindrome";
   getch();
   }