fork download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4. int main (){
  5. int n, m, arr[100][100], sum_row = 0, sum_column = 0;
  6. cin >> n >> m;
  7. for(int i = 0; i < n; i++){
  8. for(int j = 0; j < m; j++){
  9. cin >> arr[i][j];
  10. }
  11. }
  12. cout << "Row sums: ";
  13. for(int i = 0; i < n; i++){
  14. for(int j = 0; j < m; j++){
  15. sum_row += arr[i][j];
  16. }
  17. cout << sum_row << " ";
  18. sum_row = 0;
  19. }
  20. cout << endl << "Column sums: ";
  21. for(int j = 0; j < m ;j++){
  22. for(int i = 0 ; i < n; i++){
  23. sum_column += arr[i][j];
  24. }
  25. cout << sum_column << " ";
  26. sum_column = 0;
  27. }
  28. }
  29.  
Success #stdin #stdout 0.01s 5304KB
stdin
3 4
1 2 3 4
5 6 7 8 
9 10 11 12
stdout
Row sums: 10 26 42 
Column sums: 15 18 21 24