Concetti Chiave
- This C++ program is designed to handle matrices by loading, printing, and summing two matrices.
- The program uses a maximum matrix size of 50x50, as defined by the constant MAX.
- Functions include asking for dimensions, loading matrices, printing matrices, and summing two matrices.
- Matrix addition occurs only if the dimensions of both matrices match, ensuring compatibility for summation.
- The program includes a loop structure for input and output operations, using standard input and output streams.
#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 SommaMatrici(int M1[MAX][MAX], int M2[MAX][MAX], int r, int c);
int main()
{
int r, c, r1, c2;
int mat1[MAX][MAX], mat2[MAX][MAX];
cout
r=chiedidimensione();
cout
c=chiedidimensione();
Caricamento(mat1, r, c);
cout
r1=chiedidimensione();
cout
c2=chiedidimensione();
Caricamento(mat2, r1, c2);
if((r==r1 )&& (c==c2)) {
SommaMatrici(mat1, mat2, r, c);
}
else {
cout
}
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
}
}
cout
Stampa(matr,r,c);
}
void Stampa(int matr[MAX][MAX],int r,int c){
for(int x=0;x
}
void SommaMatrici(int M1[MAX][MAX], int M2[MAX][MAX], int r, int c){
int M3[MAX][MAX];
for (int i=0; i
} }
cout
Stampa(M3, r, c);
}