Advertisement
cska1312

01. Sum Matrix Columns

May 15th, 2023 (edited)
686
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. #define size 100 //define max size of colums and rows
  5.  
  6. void columnSum(int arr[size][size], int m, int n)
  7. {
  8.     int sum;
  9.     for(int i = 0; i < n; i++)
  10.     {
  11.         sum = 0;
  12.     for(int j = 0;j < m; j++)
  13.     {
  14.         sum = sum + arr[j][i];  
  15.     }
  16.         cout << sum << endl;  
  17.     }
  18. }
  19. int main()
  20. {
  21.     int arr[size][size], m ,n;
  22.     cin >> m >> n; //input size of colums and rows
  23.     for(int i = 0; i < m; i++)
  24.     {
  25.     for(int j = 0; j < n; j++)
  26.     {
  27.       cin>>arr[i][j];//input the array
  28.     }
  29.     }
  30.     columnSum(arr, m ,n);//call function
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement