Matrici
Dupa mult timp revin cu un alt tutorial si anume cu matricile.
Din tutorialele precedente, ati observat ca C++ ne permite stocarea a mai multe numere intr-o singura variabila si anume intr-un tablou unidimensional, sau cum il stim cu totii: vectorul.Tot C++ ne permite stocarea a acelorasi numere, dar intr-o forma mai organizata si mai extinsa.Ca sa intelegeti mai usor,
o matrice poate fi considerata o lista de tablouri unidimensionale
.
Exemplu de matrici:
Code:
You have to register to be able to see this link. Register HERE!
If you are already a member please log in! If you still you are not able to see the link you need to activate your account or an administrator need to activate your account!
Code:
You have to register to be able to see this link. Register HERE!
If you are already a member please log in! If you still you are not able to see the link you need to activate your account or an administrator need to activate your account!
Declararea matricilor e la fel de simpla ca declararea vectorilor.O matrice are 2 dimensiuni: un numar de linii si un numar de coloane.Astfel in primul exemplu avem 3 linii si 3 coloane, iar a 2-a 3 linii si 4 coloane.
ATENTIE!
*La fel ca la vector, parcurgerea matricilor
SE INCEPE DE LA 0
Declarare
C++ Code:
You have to register to be able to see this link. Register HERE!
If you are already a member please log in! If you still you are not able to see the link you need to activate your account or an administrator need to activate your account!
unde
-dimensiunea1 este numarul liniilor
-dimensiunea2 este numarul coloanelor
Deci, in exemplul 1 vom considera o matrice de numere naturale si o vom declara astfel:
C++ Code:
You have to register to be able to see this link. Register HERE!
If you are already a member please log in! If you still you are not able to see the link you need to activate your account or an administrator need to activate your account!
-tipul variabilei: unsigned int(matrice de numere naturale)
-numele variabilei(a matricii): a
-numarul de linii: 3
-numarul de coloane: 3
Astfel observam ca
Code:
You have to register to be able to see this link. Register HERE!
If you are already a member please log in! If you still you are not able to see the link you need to activate your account or an administrator need to activate your account!
In al doilea exemplu vom avea urmatoarea declarare:
C++ Code:
You have to register to be able to see this link. Register HERE!
If you are already a member please log in! If you still you are not able to see the link you need to activate your account or an administrator need to activate your account!
-avem 3 linii si 4 coloane
Asadar:
Code:
You have to register to be able to see this link. Register HERE!
If you are already a member please log in! If you still you are not able to see the link you need to activate your account or an administrator need to activate your account!
Acum ca am terminat partea de teorie si avem o idee despre ce inseamna o matrice, va voi invata sa cititi si sa afisati o matrice:
C++ Code:
You have to register to be able to see this link. Register HERE!
If you are already a member please log in! If you still you are not able to see the link you need to activate your account or an administrator need to activate your account!
Am ales 3 linii si 5 coloane,iar programul va arata asa:
In urmatorul tutorial va voi invata despre diagonale si inca cateva lucruri.
Sper ca ati inteles si ca v-am fost de ajutor.Pentru intrebari lasati reply va rog.Multumesc pentru atentie si spor la programat!