35657

Untitled

Dec 2nd, 2023
699
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <time.h>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     setlocale(LC_ALL, "ru");
  8.  
  9.     const int row = 3;
  10.     const int col = 4;
  11.  
  12.     int arr[row][col];
  13.  
  14.     srand(time(NULL));
  15.  
  16.     int sum = 0;
  17.  
  18.  
  19.     for (int i = 0; i < row; i++) {
  20.         for (int j = 0; j < col; j++) {
  21.             arr[i][j] = rand() % 15;
  22.         }
  23.     }
  24.  
  25.     for (int i = 0; i < row; i++) {
  26.         int row_sum = 0;
  27.         for (int j = 0; j < col; j++) {
  28.             cout << arr[i][j] << "\t";
  29.             row_sum += arr[i][j];
  30.         }
  31.         sum += row_sum;
  32.         cout << "|\t" << row_sum << endl;
  33.     }
  34.     cout << "---------------------------------" << endl;
  35.  
  36.     for (int i = 0; i < col; i++) {
  37.         int col_sum = 0;
  38.         for (int j = 0; j < row; j++) {
  39.             col_sum += arr[j][i];
  40.         }
  41.         cout << col_sum << "\t";
  42.     }
  43.     cout << " \t" << sum << endl;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment