51 lines
1019 B
C++
51 lines
1019 B
C++
// Cristian Ronzoni 3Ain
|
|
// Genera una matrice diagonale con valori casuali
|
|
// Righe nel ciclo esterno, colonne nel ciclo interno (righe i, colonne j)
|
|
|
|
#include <iostream>
|
|
#include <iomanip>
|
|
#include <ctime>
|
|
#include <cstdlib>
|
|
#define LATO 5
|
|
#define MIN 20
|
|
#define MAX 60
|
|
|
|
using namespace std;
|
|
|
|
|
|
void riempiMatrice(int arr[LATO][LATO]) {
|
|
for (size_t i = 0; i < LATO; ++i) {
|
|
for (size_t j = 0; j < LATO; ++j) {
|
|
if (i == j)
|
|
arr[i][j] = rand() % (MAX - MIN + 1) + MIN;
|
|
else
|
|
arr[i][j] = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void stampaMatrice(int arr[LATO][LATO]) {
|
|
for (size_t i = 0; i < LATO; ++i) {
|
|
for (size_t j = 0; j < LATO; ++j) {
|
|
cout << setw(3)<< arr[i][j] << " ";
|
|
}
|
|
cout << endl;
|
|
}
|
|
}
|
|
|
|
int main(void) {
|
|
|
|
|
|
|
|
|
|
int array[LATO][LATO];
|
|
|
|
|
|
riempiMatrice(array);
|
|
cout << "Matrice diagonale generata:\n";
|
|
stampaMatrice(array);
|
|
|
|
return 0;
|
|
}
|