guys i want to print a string in reverse.. and made a code.. but it's wrong.. please help me to find out the error.. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

guys i want to print a string in reverse.. and made a code.. but it's wrong.. please help me to find out the error..

#include <iostream> using namespace std; #include <string> int main() { string s; cin>>s; int n; n=s.length(); for (int n=n;n>=0;n--); cout<<s[n]; return 0; }

7th Jan 2020, 1:06 PM
Ariz imam
Ariz imam - avatar
5 Answers
+ 1
thank man..
7th Jan 2020, 1:27 PM
Ariz imam
Ariz imam - avatar
+ 1
use curly bracket except semicolon in for statement
8th Jan 2020, 4:23 AM
Sujal Uprety
Sujal Uprety - avatar
0
it worked
7th Jan 2020, 1:27 PM
Ariz imam
Ariz imam - avatar
0
but if we use for(int n=n-1;n>=0;n--) why isn't not working
7th Jan 2020, 1:31 PM
Ariz imam
Ariz imam - avatar
0
ok
7th Jan 2020, 1:33 PM
Ariz imam
Ariz imam - avatar