Advertisement
Garey

Sum By Columns With Random Numbers

Nov 7th, 2017
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1.   ////////////////////////////////////////////////////////////////////////
  2.  // Задачата събира матрицата по колони и извежда сумата под колоната. //
  3. ////////////////////////////////////////////////////////////////////////
  4. #include <iostream>
  5. #include <ctime>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.   srand(time(0));
  11.   int matrix[2][7];
  12.   int sum_columns[7];
  13.  
  14.   for (size_t i = 0; i < 2; i++) {
  15.     for (size_t j = 0; j < 7; j++) {
  16.         matrix[i][j] = rand() % (9 - 1);
  17.     }
  18.   }
  19.  
  20.   for (size_t j = 0; j < 7; j++) {
  21.     sum_columns[j] = 0;
  22.     for (size_t i = 0; i < 2; i++) {
  23.       sum_columns[j] = sum_columns[j] + matrix[i][j];
  24.     }
  25.   }
  26.  
  27.   for (size_t i = 0; i < 2; i++) {
  28.     for (size_t j = 0; j < 7; j++) {
  29.         cout << matrix[i][j] << "   ";
  30.     }
  31.     cout << endl;
  32.   }
  33.  
  34.   for (size_t i = 0; i < 7; i++) {
  35.     cout << sum_columns[i] << "   ";
  36.   }
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement