#include <iostream>
      
      using namespace std;
      // function prototype
      void reverse(const string& a);
      // function definition
      void reverse(const string& str) {
        // store the size of the string
        size_t numOfChars = str.size();
        if(numOfChars == 1) {
          cout << str << endl;
        }
        else {
          cout << str[numOfChars - 1];
          // function recursion
          reverse(str.substr(0, numOfChars - 1));
        }
      }
      
      Cpp language logo

      Reverse string with recursion

      Codiga's C++ Recipes

      Take a sentence and reverse it using recursion.

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.