35657

Untitled

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