0% found this document useful (0 votes)
14 views10 pages

Mat Rice

A matrix is a data structure that uses two indices, one for the row and one for the column, to identify elements. Elements are accessed as a[row][column]. A matrix can be declared for different data types and sizes, such as int a[10][10] for integer matrices or float b[50][50] for float matrices. Matrices can be input, processed, and output element-by-element using for loops. Special properties of square matrices include values along the main and secondary diagonals as well as the four regions divided by them. Rows and columns can be added or removed from a matrix by shifting elements and inserting new values.

Uploaded by

Carlan Marcel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views10 pages

Mat Rice

A matrix is a data structure that uses two indices, one for the row and one for the column, to identify elements. Elements are accessed as a[row][column]. A matrix can be declared for different data types and sizes, such as int a[10][10] for integer matrices or float b[50][50] for float matrices. Matrices can be input, processed, and output element-by-element using for loops. Special properties of square matrices include values along the main and secondary diagonals as well as the four regions divided by them. Rows and columns can be added or removed from a matrix by shifting elements and inserting new values.

Uploaded by

Carlan Marcel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Matrice

Crlan Marcel

Definiie
Este o structur de date n care pentru a identifica un element se folosesc doi indici, unul de linie si unul de coloan;

1 7

8 1

5 2

a[numrul liniei][numrul coloanei] ex: a[nl-1][nc] - ultimul element de pe penultima linie a[2][1] - primul element de pe a doua linie

Declararea matricei
int a[10][10]; float b[50][50];

Citirea matricei
cout << n= ;cin >> n; cout << m= ;cin >> m; for(i=1; i<=n; i++) for(j=1; j<=n; j++) cin >> a[i][j];

Preclucrarea matricei
for(i=1; i<=n; i++) for(j=1; j<=m; j++) prelucrez a[i][j];

Afisarea matricei
for(i=1; i<=n; i++) { for(i=1; j<=m; j++) cout << a[i][j] << ; cout << endl; }

Matricea patratic
1.pe diagonala principal a.i=j; b.for(i=1; i<=n; i++) prelucrez a[i][i]; 2. sub diagonala principal a.i>j; b.for(i=2; i<=b; i++) for(j=1; j<=i-1; j++) prelucrez a[i][j];

Matricea patratic
3. deasupra diagonalei principale a.i>j b.for(i=1; i<=n-1; i++) for(j=i+1; j<=n; j++) prelucrez a[i][j]; 4. pe diagonala secundar a.i+j=n+1 b.for(i=1; i<=n; i++) prelucrez a[i][n-i+1];

Matricea patratic
5. deasupra diagonalei secundare a.i+j<n+1 b.for(i=1; i<=n-1; i++) for(j=1; j<=n-1; j++) prelucrez a[i][j]; 6. sub diagonala secundar a.i+j>n+1 b.for(i=2; i<=n; i++) for(j=n-1+2; j<=n; j++) prelucrez a[i][j];

Adugarea sau tergerea de linii sau coloane


I. linie nl++; for(i=nl; i>=p; i--) for(j=1; j<=nc; j++) a[i][j]=a[i-1][j]; for(j=1; j<=nc; j++) a[i][j]=y; II. coloan nc++; for(i=nc; i<=p; i--) for(j=1; j<=nl; j++) a[i][j]=a[j][i-1]; for(j=1; j<=nl; j++) a[j][i]=y;

You might also like