Palindrome string program in C++

bookmark

#include<iostream.h>
#include<conio.h>
#include <string.h>
void main()
{
	clrscr();
	char str1[30], str2[30] ;
	cout<<"Enter a string : \n";
	cin>>str1
	strcpy(str2,str1);     //copying str1 in str 2
	strrev(str2);         //reversing string 2
	if( strcmp(str1, str2) == 0 ) //compare the original and reversed string
		cout<<"\n The string is a palindrome.\n";
	else
		cout<<"\n The string is not a palindrome.\n";
	getch();
}

 

Output:

Enter a string:

Hello

The string is not a palindrome.