Column Wise Sum
Column Wise Sum
Send Feedback
Column Wise Sum
First and only line of input contains M and N, followed by M * N space separated integers representing the elements in the 2D array.
Sum of every ith column elements (separated by space)
4 2 1 2 3 4 5 6 7 8
16 20
#include<iostream>using namespace std;
int main(){
/* Read input as specified in the question. * Print output as specified in the question. */ int sum; int n,m; cin>>n>>m; int array[n][m]; for(int i=0;n>i;i++){ for(int j=0;j<m;j++){ cin>>array[i][j]; } } for(int i=0;i<m;i++){ sum=0; for(int j=0;j<n;j++){ sum=sum+array[j][i]; } cout<<sum<<" "; } // for(int j=0;j<m;j++){// for(int i=0;i<n;i++){// sum=sum+array[j][i]; // }// cout<<sum<<" ";// } }
Comments
Post a Comment