i have tried my code after looking for some solutions online. There was one algorithm regarding string reversal via recursion and i tried my best to make my code according to that algorithm. unfortunately, my code only swaps the first and the last characters in the given string but not the characters second with second last and so on. any help would be appreciated here's my code:
string reverse(string s,int length,int start=0){
if (start>=length){
return s;
}
else{
char temp=s[length];
s[length]=s[start];
s[start]=temp;
reverse(s,--length,++start);
}return s;
}
int main(void) {
string a;cout<<"enter a string:";getline(cin,a);
cout<<reverse(a,a.length()-1,0);
}