Palindrome using string | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Palindrome using string

check for a number and a character whether it is palimdrome or not

2nd Mar 2017, 2:48 PM
Bhavya Goel
Bhavya Goel - avatar
2 Answers
+ 2
Try for a recursive algorithm: 1. if the string has length <=1, it's a palindrome. 2. else, the string is a palindrome if its initial and ending characters are equal, and the inner characters form a palindrome string.
2nd Mar 2017, 3:53 PM
Álvaro
0
This code should reverse the stirng #include <iostream> using namespace std; int main() { string s; char c; int l; s="sololearn"; l=s.size(); for(int i=0;i<s.size()/2+1;i++){ c=s[i]; s[i]=s[l-i-1]; s[l-i-1]=c; } cout<<s; } the output is "nraelolos" and then you compare the strings
2nd Mar 2017, 3:38 PM
Matteo Protopapa
Matteo Protopapa - avatar