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

Matrice: Definiție și Prelucrare

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)
35 views10 pages

Matrice: Definiție și Prelucrare

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

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
[Link] diagonala principal a.i=j; [Link](i=1; i<=n; i++) prelucrez a[i][i]; 2. sub diagonala principal a.i>j; [Link](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 [Link](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 [Link](i=1; i<=n; i++) prelucrez a[i][n-i+1];

Matricea patratic
5. deasupra diagonalei secundare a.i+j<n+1 [Link](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 [Link](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;

Common questions

Powered by AI

To add a new row at a specified position, increment the total number of rows 'nl', shift existing rows by iterating backward from the last row to the specified position, and assign their values to the next row to make space. Then, initialize the new row at the desired position with desired values .

To process elements above the main diagonal of a square matrix, iterate over rows and columns such that the column index is greater than the row index. This can be achieved with a loop where 'for(i=1; i <= n-1; i++)' and 'for(j=i+1; j <= n; j++)', processing 'a[i][j]' within this nested loop structure .

Elements on the main diagonal of a matrix are identified where the row index equals the column index, i.e., i=j. In an iterative approach, this means processing 'a[i][i]' for each loop iteration where this condition is met .

For pre-processing elements in an n by m matrix, use two nested loops: the outer loop to iterate over rows 'for(i=1; i<=n; i++)' and the inner loop to iterate over columns 'for(j=1; j<=m; j++)', and apply the desired processing operation on each element 'a[i][j]' .

Processing elements on and under the main diagonal involves iterating over the matrix where the row index is greater than or equal to the column index, i.e., 'i>=j'. This encompasses processing 'a[i][j]' for '1 <= i <= n' and '1 <= j <= i'. This method traverses both the diagonal and the lower triangle of a matrix .

When declaring a matrix in C++, you must decide the data type (e.g., int, float), sizes for both the number of rows and columns, and understand the matrix's memory layout. For example, 'int a[10][10];' declares a 10x10 matrix of integers, with distinct memory allocation considerations for efficient access and manipulation .

Elements below the secondary diagonal of a square matrix can be iterated by ensuring that the sum of the indices i and j is greater than n+1. This is executed with a nested loop structure 'for(i=2; i<=n; i++)' and 'for(j=n-i+2; j<=n; j++)', and processing each 'a[i][j]' .

The condition i+j=n+1 is significant in matrices as it identifies the elements on the secondary diagonal, where i represents the row index and j represents the column index in an n×n square matrix. This diagonal runs from the top-right corner to the bottom-left corner of the matrix, distinctly described by this condition .

When adding a column, 'nc' is incremented, and columns are shifted right by iterating from the last column to the specified position. For rows, 'nl' is incremented, and rows are shifted down from the last row to the desired position. Both involve initializing a new position with specific values after space is made .

In a matrix, elements are accessed using two indices: one for the row and one for the column, such as a[row][column]. In contrast, a simple array uses a single index to access elements, like a[index]. This allows matrices to represent two-dimensional data structures, unlike arrays which are one-dimensional .

You might also like