Question: In c++ make this program to reverse a string use recursion instead of iteration to reverse the string. #include #include using namespace std; string Backwards(string);

In c++ make this program to reverse a string use recursion instead of iteration to reverse the string.

#include #include using namespace std;

string Backwards(string);

int main() { string s;

cout << "Enter string: "; cin >> s; Backwards(s); }

string Backwards(string s) { int starting = s.length(); int ending = starting - 1; int i = 0;

while(i <= ending) { swap(s[i],s[ending]); ending -= 1; i += 1; }

cout << s; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!