Guest

reverse

Jan 11th, 2026
17
0
Never
Not a member of gistpad yet? Sign Up, it unlocks many cool features!
C++ 3.43 KB | Source Code | 0 0
  1. // SpiderX Code
  2.  
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int main() {
  7. string str;
  8. cout << "Enter a string: ";
  9. getline(cin, str);
  10.  
  11. // calculate length of string
  12. int strLen = str.length() - 1;
  13.  
  14. // store reverse string
  15. string reversedStr = "";
  16.  
  17. for (int i = strLen; i >= 0; i--) {
  18. reversedStr += str[i];
  19. }
  20.  
  21. cout << "\nOriginal String: " << str << endl;
  22.  
  23. cout << "Reversed string: " << reversedStr << endl;
  24.  
  25. return 0;
  26. }
RAW Gist Data Copied