35657

Untitled

Dec 2nd, 2023
536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4. using namespace std;
  5.  
  6.  
  7. int main() {
  8.     setlocale(LC_ALL, "ru");
  9.  
  10.     const int row = 3;
  11.     const int col = 3;
  12.  
  13.     int arr[row][col];
  14.  
  15.     srand(time(NULL));
  16.  
  17.     int sum = 0;
  18.  
  19.     for (int i = 0; i < row; i++) {
  20.         for (int j = 0; j < col; j++) {
  21.             arr[i][j] = rand() % 10;
  22.             cout << arr[i][j] << '\t';
  23.         }
  24.         cout << endl;
  25.     }
  26.     cout << endl;
  27.  
  28.     int min = arr[0][0];
  29.     int max = arr[0][0];
  30.  
  31.     for (int i = 0; i < row; i++) {
  32.         for (int j = 0; j < col; j++) {
  33.             sum += arr[i][j];
  34.             if (arr[i][j] < min) {
  35.                 min = arr[i][j];
  36.             }
  37.             if (arr[i][j] > max) {
  38.                 max = arr[i][j];
  39.             }
  40.         }
  41.         cout << endl;
  42.     }
  43.  
  44.     cout << "Сумма всех элементов массива: " << sum << endl;
  45.     cout << "Среднее арифметическое: " << sum / (row * col) << endl;
  46.     cout << "Минимальный элемент: " << min << endl;
  47.     cout << "Максимальный элемент: " << max << endl;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment