mirror of
https://github.com/c0de-archive/hacktoberfest-2018.git
synced 2024-12-22 13:22:39 +00:00
Create reversestrin.cpp
This commit is contained in:
parent
4da95e9a22
commit
c7bf836a88
21
code/reversestrin.cpp
Normal file
21
code/reversestrin.cpp
Normal 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));
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user