+ 2

Convert string as palindrome without any predefined methods

If string is jyo8j, need to insert o, y in 5,6 positions. And calculate no of insertions. Which can be done dynamically

14th Sep 2018, 4:52 PM
Jyothsna Sattenapalli
Jyothsna Sattenapalli - avatar
2 Answers
+ 1
#include <iostream> #include <stdlib.h> using namespace std; int main(){ int n=0; string s; cout<<"Enter String: "; cin>>s; for(int k=s.length()-1,i=0 ; k>=0,i<s.length() ; --k,++i){ if(s[k]==s[i]){ n++; } } if(n==s.length()){ cout<<"Palindrome"; }else{ cout<<"not Palindrome"; } return 0; }
17th Sep 2018, 5:24 PM
Deep Patel
Deep Patel - avatar