Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     srand(time(nullptr));
  9.     const int ROWS = 4, COLUMNS = 5;
  10.     int table[ROWS][COLUMNS];
  11.     int sumNegative = 0;
  12.  
  13.     for (int i = 0; i < ROWS; i++)
  14.     {
  15.         for (int j = 0; j < COLUMNS; j++)
  16.         {
  17.             table[i][j] = rand() % (10 - -10) + -10;
  18.             cout << table[i][j] << " ";
  19.         }
  20.         cout << endl;
  21.     }
  22.     for (int i = 0; i < ROWS; i++)
  23.     {
  24.         for (int j = 0; j < COLUMNS; j++)
  25.         {
  26.             if (table[i][j] < 0)
  27.             {
  28.                 sumNegative += table[i][j];
  29.             }
  30.         }
  31.     }
  32.     cout << "Total sum of negatives is: " << sumNegative << endl;
  33.     system("pause");
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement