-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrix column sum.cpp
54 lines (42 loc) · 936 Bytes
/
Matrix column sum.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
Given a matrix of size N x M, print column-wise sum, separated by a newline.
Input Format
The first line of input contains N, M - the size of the matrix. Its followed by N lines each containing M integers - elements of the matrix.
Constraints
1 <= N, M <= 100
-106 <= ar[i] <= 106
Output Format
Print column-wise sum of the matrix, separated by newline.
Sample Input 0
2 2
5 -1
19 8
Sample Output 0
24
7
*/
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int N,M,sum=0;
cin>>N>>M;
int A[N][M];
for(int i=0;i<N;i++){
for(int j=0;j<M;j++){
cin>>A[i][j];
}
}
for(int j=0;j<M;j++){
for(int i=0;i<N;i++){
sum=sum+A[i][j];
}
cout<<sum<<endl;
sum=0;
}
return 0;
}