Explanation
May I ask you to expain to me how this works? What is what, and why is it so?
Thansk in fornt.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
string unesi, piramida;
cout << "Unesite brojeve ili slova: ";
cin >> unesi;
string prostor (unesi.length() - 1, ' ');
for (size_t i{0}; i < unesi.length(); ++i) {
piramida = unesi.substr(0, i + 1);
cout << prostor << piramida;
if (piramida.length() == 1) {
cout << prostor;
} else {
for (auto j {piramida.length()}; j > 0; --j) {
cout << piramida.at(j-1);
}
}
prostor.erase(0, 1);
cout << endl;
}
return 0;
|
> May I ask you to expain to me how this works?
1. Run it and find out.
1 2 3 4 5 6 7
|
$ ./a.out
Unesite brojeve ili slova: hello
h
heeh
helleh
helllleh
helloolleh
|
2. It's software, so you could try deleting things and observing the change in behavior.
Eg.
//prostor.erase(0, 1);
1 2 3 4 5 6 7
|
$ ./a.out
Unesite brojeve ili slova: hello
h
heeh
helleh
helllleh
helloolleh
|
Topic archived. No new replies allowed.