Advertisement
Spocoman

01. Sum Matrix Columns

Jan 26th, 2024 (edited)
904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int row, col, el;
  8.     cin >> row >> col;
  9.  
  10.     vector<vector<int>> matrix;
  11.    
  12.     for (int i = 0; i < row; i++) {
  13.         vector<int> currentRow;
  14.         for (int j = 0; j < col; j++) {
  15.             cin >> el;
  16.             currentRow.push_back(el);
  17.         }
  18.         matrix.push_back(currentRow);
  19.     }
  20.  
  21.     for (int i = 0; i < col; i++) {
  22.         int sum = 0;
  23.         for (int j = 0; j < row; j++) {
  24.             sum += matrix[j][i];
  25.         }
  26.         cout << sum << endl;
  27.     }
  28.  
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement