My Blog

My WordPress Blog

My Blog

My WordPress Blog

Write a C++ Program to Print the Given String in Reverse Order Using Recursion

C++// C++ Program to // Reverse string using // recursion #include <iostream> using namespace std; void reverse_str(string& s, int n, int i) { if (n <= i) { return; } swap(s[i], s[n]); reverse_str(s, n - 1, i + 1); } int main() { string str = "GeeksforGeeks"; reverse_str(str, str.length() - 1, 0); cout << str << endl; }

Output

skeeGrofskeeG
Write a C++ Program to Print the Given String in Reverse Order Using Recursion

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top