Wed Nov 06 2019

Palindrome String

C++ Programming1601 views

File Name: palindrome-string.cpp

#include<iostream> 

/* Contains functions for manipulating data */
#include<algorithm>
using namespace std; 

int main() {

	/* Declear string type variable in C++ */
	string str;
	cout << "Check the given string is Palindrome or not" << endl;
	cout << "Enter a string:" << endl; 
	cin >> str; 
	
	/* begin() and end() rbegin() are iterators for beginning and end */
	/* equal() compares the elements */
	if(equal(str.begin(), str.end(), str.rbegin()))
        	cout << "It's a palindrome string" << endl; 
	else 
		cout << "It's not a palindrome string!" << endl; 

	return 0;
}



/* Output */
Check the given string is Palindrome or not
Enter a string:
abcba

It's a palindrome string!



/* ---------------------------------- */



Check the given string is Palindrome or not
Enter a string:
asdfg

It's not a palindrome string!
Reference:

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.