Advertisement
Garey

Sum By Rows With Random Numbers

Nov 7th, 2017
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 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_rows[2];
  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 i = 0; i < 2; i++) {
  21.     sum_rows[i] = 0;
  22.     for (size_t j = 0; j < 7; j++) {
  23.         cout << matrix[i][j] << "   ";
  24.         sum_rows[i] = sum_rows[i] + matrix[i][j];
  25.     }
  26.     cout << sum_rows[i] << endl;
  27.   }
  28.  
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement