Create reversestrin.cpp

This commit is contained in:
Apostropheqq 2018-10-07 23:33:36 +02:00 committed by GitHub
parent 4da95e9a22
commit c7bf836a88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 0 deletions

21
code/reversestrin.cpp Normal file
View File

@ -0,0 +1,21 @@
#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));
}