#include
#define MAX 50
using namespace std;
int chiedidimensione();
void Caricamento(int M[MAX][MAX], int r, int c);
void Stampa(int M[MAX][MAX],int r,int c);
void Max(int M[MAX][MAX], int r, int c);
void Min(int M[MAX][MAX], int r, int c);
void DiagonalePrincipale(int M[MAX][MAX], int r, int c);
int main()
{
int r, c;
int M[MAX][MAX];
cout
r=chiedidimensione();
cout
c=chiedidimensione();
Caricamento(M, r, c);
Max(M, r, c);
Min(M, r, c);
DiagonalePrincipale(M,r,c);
return 0;
}
int chiedidimensione()
{
int d;
do{
cin>>d;
}while(dMAX);
return d;
}
void Caricamento(int M[MAX][MAX], int r, int c){
cout
for(int x=0; x
for(int y=0; y
cin>>M[x][y];
}
}
cout
Stampa(M,r,c);
}
void Stampa(int M[MAX][MAX],int r,int c){
for(int x=0;x
for(int y=0; y
cout
}cout
}
}
void Max(int M[MAX][MAX], int r, int c){
int max;
for(int i=0;i
for(int j=0; j
if(max
max=M[j];
}
} }
cout
}
void Min(int M[MAX][MAX], int r, int c) {
int min;
for(int i=0; i
for(int j=0; j
if(min>M[j]) {
min=M[j];
}
} }
cout
}
void DiagonalePrincipale(int M[MAX][MAX], int r, int c)
{
cout
for(int i=0; i
for(int j=0; j
if(i==j){
cout[j];
}
}
}
}
Domande da interrogazione
- What is the purpose of the `chiedidimensione` function in the code?
- How does the code handle the input and storage of matrix elements?
- What is the role of the `DiagonalePrincipale` function in the program?
The `chiedidimensione` function is designed to prompt the user to input a dimension for the matrix, ensuring that the input is within a valid range (greater than 0 and less than or equal to MAX).
The code uses the `Caricamento` function to input and store matrix elements. It iterates over the matrix dimensions, prompting the user to input values for each element, and then calls the `Stampa` function to display the matrix.
The `DiagonalePrincipale` function is responsible for printing the elements of the main diagonal of the matrix. It checks if the row index equals the column index and prints the corresponding element.