School-Coding-Cpp/sfusi/4x5SommaEleColVett.cpp

26 lines
620 B
C++

//Patriche Robert Cosmin
#include <iostream>
using namespace std;
void sommaColonne(int matrice[4][5], int righe, int colonne) {
int somma[5] = {0};
for (int i = 0; i < righe; i++) {
for (int j = 0; j < colonne; j++) {
somma[j] += matrice[i][j];
}
}
cout << "Somma per colonna: ";
for (int j = 0; j < colonne; j++) {
cout << somma[j] << " ";
}
cout << endl;
}
int main() {
int matrice[4][5] = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}, {11, 12, 13, 14, 15}, {16, 17, 18, 19, 20}};
sommaColonne(matrice, 4, 5);
return 0;
}