- 1

coding on how to reverse a word

14th Sep 2016, 10:05 AM
Jaideep Sosa
Jaideep Sosa - avatar
2 Answers
+ 1
http://www.sololearn.com/app/cplusplus/playground/cLPV0Tjw08xz/ #include <iostream> #include <string> #include <algorithm> using namespace std; int main() { string word; cout << "Enter a word to reverse: "; cin >> word; reverse(word.begin(), word.end()); cout << "Reversed word: " << word << endl; return 0; }
14th Sep 2016, 12:12 PM
kiwiyou
kiwiyou - avatar
+ 1
A different way, without algorithm: #include <iostream> #include <string> using namespace std; int main() { string str; cout << "Enter a string: "; getline(cin, str); for (int i = str.length() - 1; i >= 0; i--) cout << str.at(i); }
14th Sep 2016, 2:41 PM
Cohen Creber
Cohen Creber - avatar