SHARE
TWEET

Enter Matrix + Print Sum Raw

daniil_mironoff Mar 30th, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top