Advertisement
ULK

Лабораторная №9 (12.68б)

ULK
Dec 6th, 2022 (edited)
830
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int const m = 5;
  7.     int const n = 5;
  8.     int a[m][n];
  9.  
  10.     int c = 0;
  11.     int i, j;
  12.     int sum = 0;
  13.  
  14.     srand(time(0));
  15.  
  16.     for (i = 0; i < m; i++) {  //создаём матрицу
  17.         for (j = 0; j < n; j++) {
  18.             a[i][j] = 20 + rand() % 100;
  19.             cout << a[i][j] << "\t";
  20.         }
  21.         cout << endl;
  22.     }
  23.  
  24.     for (j = 0; j < n; j++) {  //прогоняемся по 4ой строке
  25.         if (a[3][j] % 3 == 0) {
  26.             sum = sum + a[3][j];
  27.             c++;
  28.         }
  29.  
  30.     }
  31.     cout << "\n";
  32.     cout << "Arithmetic mean of the elements of the 4th row that are multiples of 3: " << sum / c << endl;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement