From e1df371f24cfd5d4481a989f72534023e5cb894e Mon Sep 17 00:00:00 2001 From: Omkar Patil Date: Mon, 2 Oct 2023 12:58:01 +0530 Subject: [PATCH] added Reverse a string using C++ as requested --- Python/reversestring.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Python/reversestring.cpp diff --git a/Python/reversestring.cpp b/Python/reversestring.cpp new file mode 100644 index 0000000..778ea38 --- /dev/null +++ b/Python/reversestring.cpp @@ -0,0 +1,25 @@ +#include +#include +using namespace std; + +int main() { + string str; + cout << "Enter a string: "; + cin >> str; + + int start = 0; + int end = str.length() - 1; + + while (start < end) { + // Swap characters at start and end positions + char temp = str[start]; + str[start] = str[end]; + str[end] = temp; + + start++; + end--; + } + + cout << "Reversed string: " << str << endl; + return 0; +} \ No newline at end of file