Advertisement
daniil_mironoff

Enter Matrix + Print Sum Raw

Mar 30th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace  std;
  4.  
  5. int main() {
  6.     int sizeX;
  7.     cout << "Enter sizeX: ";
  8.     cin >> sizeX;
  9.    
  10.     int sizeY;
  11.     cout << "Enter sizeY: ";
  12.     cin >> sizeY;
  13.    
  14.     int ** arr = new int * [sizeY];
  15.    
  16.     for (int i = 0; sizeY > i; i++) {
  17.         arr[i] = new int [sizeX];
  18.         for (int j = 0; sizeX > j; j++) {
  19.             cout << "Enter arr[" << i << "][" << j << "]: ";
  20.             cin >> arr[i][j];
  21.         }
  22.     }
  23.    
  24.     cout << endl;
  25.    
  26.     for (int i = 0; sizeY > i; i++) {
  27.         for (int j = 0; sizeX > j; j++) {
  28.             cout << arr[i][j] << " ";
  29.         }
  30.        
  31.         cout << endl;
  32.     }
  33.    
  34.     cout << endl;
  35.    
  36.     for (int i = 0; sizeX > i; i++) {
  37.         int sum = 0;
  38.        
  39.         for (int j = 0; sizeY > j; j++) {
  40.             sum += arr[j][i];
  41.         }
  42.        
  43.         cout << sum << endl;
  44.     }
  45.    
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement