Sunday 21 December 2014

Palindrome

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
char *ptr;
int i=0,j=0,k=0,len=0;
char str1[20];
cout<<"Enter a string:";
gets(str1);
cout<<endl<<"Original string is:";
puts(str1);
ptr=str1;
for(i=0;*(ptr+i)!='\0';i++)
{
      len++;
}
for(i=0,j=len-1;i<=len/2;i++,j--)
{
     if( *(ptr+i)==*(ptr+j) )
     k=1;
}
if(k==1)
cout<<endl<<"Palindrone";
else
cout<<endl<<"Not a Palindrone";
getch();
}

No comments:

Post a Comment