hacktoberfest-2018/code/reversestrin.cpp
2018-10-07 23:33:36 +02:00

22 lines
383 B
C++

#include <iostream>
using namespace std;
void reverse(const string& a);
int main()
{
string str;
cout << " Please enter a string " << endl;
getline(cin, str);
reverse(str);
return 0;
}
void reverse(const string& str)
{
size_t numOfChars = str.size();
if(numOfChars == 1)
cout << str << endl;
else
{
cout << str[numOfChars - 1];
reverse(str.substr(0, numOfChars - 1));
}