fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. const int ROWS = 5;
  7. const int COLS = 5;
  8.  
  9. int arr[ROWS][COLS];
  10.  
  11. int sum[ROWS][2]{};
  12. //srand(time(NULL));
  13.  
  14. for (int i = 0; i < ROWS; i++)
  15. {
  16. for (int j = 0; j < COLS; j++)
  17. {
  18. cout << (arr[i][j] = rand() % 21 - 5) << "\t";
  19. sum[i][0] += arr[i][j];
  20. if (arr[i][j] < 0) sum[i][1] = 1;
  21. }
  22. cout << endl;
  23. }
  24.  
  25. for (int i = 0; i < ROWS; i++)
  26. {
  27. cout << "Row " << i << ": ";
  28. if (sum[i][1])
  29. cout << "has negative numbers\n";
  30. else
  31. cout << "sum = " << sum[i][0] << endl;
  32. }
  33. }
  34.  
Success #stdin #stdout 0.01s 5360KB
stdin
Standard input is empty
stdout
-4	-1	4	14	3	
5	5	4	10	5	
-3	14	15	-1	15	
2	-2	10	11	11	
12	9	7	4	-3	
Row 0: has negative numbers
Row 1: sum = 29
Row 2: has negative numbers
Row 3: has negative numbers
Row 4: has negative numbers