Skip to content

Commit

Permalink
Create ReverseString.cpp
Browse files Browse the repository at this point in the history
Reverse String Program ravya1108#94
  • Loading branch information
tushar453 authored Oct 10, 2023
1 parent 1c13757 commit 519c254
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions ReverseString.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
#include <string>

void reverseString(std::string& str) {
int left = 0;
int right = str.length() - 1;

while (left < right) {
std::swap(str[left], str[right]);
left++;
right--;
}
}

int main() {
std::string inputString;

// Ask the user to input a string
std::cout << "Enter a string: ";
std::cin >> inputString;

// Reverse the string in-place
reverseString(inputString);

// Display the reversed string
std::cout << "Reversed string: " << inputString << std::endl;

return 0;
}

0 comments on commit 519c254

Please sign in to comment.