School-Coding-Cpp/sfusi/moltiplica matrice.cpp

50 lines
1.0 KiB
C++

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>
#define MAX 5
#define MIN 1
using namespace std;
void riempiMatrice(int matrice[][3], size_t RIGHE, size_t COLONNE){
for(size_t i = 0; i < RIGHE; i++)
{
for(size_t j = 0; j < RIGHE; j++)
{
matrice[i][j]=rand()%(MAX-MIN+1)+MIN;
cout << setw(6) << matrice[i][j];
}
cout << endl;
}
cout << endl << endl << endl;
}
int moltiplicaMatrice(int matrice[][3], size_t RIGHE, size_t COLONNE, size_t valore){
int prodotto = 1;
for(size_t k = 0; k < RIGHE; k++)
{
for(size_t l = 0; l < COLONNE; l++)
{
prodotto *= matrice[k][l];
}
}
return prodotto*valore;
}
int main(void){
srand(time(NULL));
int matrice[3][3];
const int RIGHE = 3;
const int COLONNE = 3;
int valore;
riempiMatrice(matrice, RIGHE, COLONNE);
cout << endl << endl;
cout << "inserisci il numero che moltiplica gli elementi della matrice" << endl << "-> ";
cin >> valore;
cout << moltiplicaMatrice(matrice, RIGHE, COLONNE, valore);
return 0;
}