#include

#define MAX 50

using namespace std;

int chiedidimensione();

void Caricamento(int matr[MAX][MAX], int r, int c);

void Stampa(int matr[MAX][MAX],int r,int c);

void max(int mat[MAX][MAX], int r, int c);

void min(int mat[MAX][MAX], int r, int c);

void DiagonalePrincipale(int matr[MAX][MAX], int r, int c);

int main()

{

int r, c;

int mat[MAX][MAX];

cout

r=chiedidimensione();

cout

c=chiedidimensione();

Caricamento(mat, r, c);

Stampa(mat, r, c);

max(mat, r, c);

min(mat, r, c);

DiagonalePrincipale(mat,r,c);

return 0;

}

int chiedidimensione()

{

int d;

do{

cin>>d;

}while(dMAX);

return d;

}

void Caricamento(int matr[MAX][MAX], int r, int c){

cout

for(int x=0; x

for(int y=0; y

cin>>matr[x][y];

}

}

cout

Stampa(matr,r,c);

}

void Stampa(int matr[MAX][MAX],int r,int c){

for(int x=0;x

for(int y=0; y

cout

}cout

}

}

void max(int mat[MAX][MAX], int r, int c)

{

int cont=0;

int max;

for(int i=0; i

for(int j=0; j

if(cont==0){

max=mat[j];

}

else{

if(mat[j]>max){

max=mat[j];

}

}

cont=cont+1;

}

}

cout

}

void min(int mat[MAX][MAX], int r, int c)

{

int cont=0;

int min;

for(int i=0; i

for(int j=0; j

if(cont==0){

min=mat[j];

}

else{

if(mat[j]

min=mat[j];

}

}

cont=cont+1;

}

}

cout

}

void DiagonalePrincipale(int matr[MAX][MAX], int r, int c)

{

for(int i=0; i

for(int j=0; j

if(i==j){

cout[j];

}

}

}

}

Domande da interrogazione

  1. How does the program handle matrix dimension input?
  2. The program uses the function `chiedidimensione()` to prompt the user for matrix dimensions, ensuring they are within the defined maximum limit of 50.

  3. What is the purpose of the `Caricamento` function in the program?
  4. The `Caricamento` function is responsible for populating the matrix with user input values and then calling the `Stampa` function to display the matrix.

  5. How does the program determine the maximum and minimum values in the matrix?
  6. The program uses the `max` and `min` functions to iterate through the matrix elements, comparing each to find and print the maximum and minimum values, respectively.

Domande e risposte

Hai bisogno di aiuto?
Chiedi alla community