Trebuie sa citesc numere de la tastatura pana in momentul cand intalnesc 0 , apoi sa afisez daca sirul de numere citit este crescator , descrescator sau random.
exemple :
1 3 3 4 5 5 6 - crescator
7 5 4 4 2 1 1 - descrescator
7 2 8 5 5 4 2 3 - random
Sunt la inceput si nu prea ma descurc in while....inteleg ce face dar imi e destul de greu sa implementez.
Problema trebuie facuta doar cu while/if ....fara for !
Pana acum am facut ceva de genul , dar stiu ca nu e bine:
Cod: Selectaţi tot
#include <iostream>
using namespace std;
int main() {
int x , y , z;
cin >> x;
while (y != 0) {
z = 0;
if (x <= y) {
z = 1;
} else if (y <= x) {
z = 2;
} else {
z = 3;
}
x = y;
cin >> y;
}
if (z == 1) {
cout << "crescator";
} else if (z == 2) {
cout << "descrescator";
} else {
cout << "random";
}
return 0;
}