This is a simple program to find out whether the entered string is a palindrome or not.
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
int main()
{
int a,b=0,c,d,e,f;
char str1[100],str2[100];
cout<<"Enter the string \n";
gets(str1);
for(a=0;str1[a]!='\0';a++)
b++;
b=b-1;
for(c=0;str1[c]!='\0';c++)
{
str2[b]=str1[c];
b--;
}
cout<<"The reverse of the String is :\n";
for(a=0;str1[a]!='\0';a++)
cout<<str2[a];
cout<<"\n\n";
for(c=0;str1[c]!='\0';c++)
{
if(str1[c]==str2[c])
cout<<"";
else
{
cout<<"The string is not a palindrome \n";
getch();
exit(0);
}
}
cout<<"IT is a palindrome\n";
getch();
}
OUTPUT
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
int main()
{
int a,b=0,c,d,e,f;
char str1[100],str2[100];
cout<<"Enter the string \n";
gets(str1);
for(a=0;str1[a]!='\0';a++)
b++;
b=b-1;
for(c=0;str1[c]!='\0';c++)
{
str2[b]=str1[c];
b--;
}
cout<<"The reverse of the String is :\n";
for(a=0;str1[a]!='\0';a++)
cout<<str2[a];
cout<<"\n\n";
for(c=0;str1[c]!='\0';c++)
{
if(str1[c]==str2[c])
cout<<"";
else
{
cout<<"The string is not a palindrome \n";
getch();
exit(0);
}
}
cout<<"IT is a palindrome\n";
getch();
}
OUTPUT
ABOUT THE AUTHOR
Hello, I am Piyush Ranjan, a computer engineering student from India. I love coding and talking on technology. Most of the time I am glued to my laptop watching movies, listening songs, blogging or coding.
0 comments:
Post a Comment
Thanks for your feedback !