0

Why it give me " No Output" ????

#include <iostream> using namespace std; int main() { string a,b; cin >> a ; int a1 = a.size () ; int j = 0 ; for (int i = a1 ; i<0 ; i++) { b[j] = a[i] ; j++ ; } cout <<b; return 0; }

26th May 2017, 8:54 PM
Nour Alnaser
Nour Alnaser - avatar
3 Respuestas
+ 3
#include <iostream> using namespace std; int main () { string a; cin >> a; for (int i = a.size() - 1; i >= 0; i--) { cout << a[i]; } return 0; }
26th May 2017, 9:12 PM
Emore Anzolin
Emore Anzolin - avatar
+ 3
in the for cyclus you should decrease i, if you want to reverse the input. i-- j and b are not needed
26th May 2017, 9:17 PM
Emore Anzolin
Emore Anzolin - avatar
+ 1
there might be other issues not sure but for your for loop you have int i = a1;i<0;i++. I think you want int i = 0;i<a1;i++. because currently the loop isnt running at all since its checking if i is less then 0 it will continue the loop yet it starts at a number higher then 0. hope this helped somewhat. edit: just realized if your trying to reverse the string i = a1;i>0;i--
26th May 2017, 9:14 PM
Trevor