Computer Science, asked by nickname4312, 10 months ago

Write a recursive program that inputs a line of characters from the user. The line may contain blanks. It outputs the line with the characters reversed. The input ends with eof (end of file). 



note: you have to use recursion to solve this, and are not allowed to use array to store the input!! 



example: 



input 



this is easy 



output 



ysae si siht

Answers

Answered by Anonymous
0

Answer:

C++ program to reverse a string using recursion

#include <bits/stdc++.h>

using namespace std;

/* Function to print reverse of the passed string */

void reverse(string str)

{

if(str.size() == 0)

{

return;

}

reverse(str.substr(1));

cout << str[0];

}

/* Driver program to test above function */

int main()

{

string a = "Geeks for Geeks";

reverse(a);

return 0;

}

// This is code is contributed by rathbhupendra

Output:

skeeG rof skeeG

Similar questions