School-Coding-Cpp/sfusi/CalcConfrontiCercareMassRes...

30 lines
773 B
C++

//Patriche Robert Cosmin
#include <iostream>
using namespace std;
void trovaMassimo(int matrice[3][3], int righe, int colonne) {
int max = matrice[0][0];
int x = 0, y = 0;
int confronti = 1;
for (int i = 0; i < righe; i++) {
for (int j = 0; j < colonne; j++) {
confronti++;
if (matrice[i][j] > max) {
max = matrice[i][j];
x = i;
y = j;
}
}
}
cout << "Numero di confronti: " << confronti << endl;
cout << "Massimo trovato: " << max << " alle coordinate (" << x << ", " << y << ")" << endl;
}
int main() {
int matrice[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
trovaMassimo(matrice, 3, 3);
return 0;
}