Username77177

Dahl-Programming-Lab6-5

Jan 8th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstdlib>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7. int main()
  8. {
  9.     //N_5x4. Определить сумму отриц элементов в каждом столбце
  10.     srand(time(0));
  11.     int N[5][4]; //Создаём и заполняем двухмерный массив
  12.     for (int i = 0; i<5; i++) {
  13.         for (int j = 0; j<4; j++) {
  14.             N[i][j] = rand() % 30 - 15;
  15.             // cout<<N[i][j]<<endl;
  16.         }
  17.     }
  18.     //Variables
  19.     int sum = 0, jealous = 1;
  20.     //
  21.     for (int i = 0; i<5; i++) {
  22.         sum = 0;
  23.         for (int j = 0; j < 4; j++) {
  24.             if (N[i][j]<0) {
  25.                 sum += N[i][j];
  26.             }
  27.         }
  28.         cout<<"В столбце "<<jealous<< " сумма отрицательных элементов равна "<< sum<<"\n";
  29.         jealous++;
  30.     }
  31.     //Задание 2: а) Номер столбца, где находится мин эл 4 строки. Если таких несколько то выбрать самый левый
  32.     int min = N[3][0];
  33.     int index = 0;
  34.     for (int i = 0; i< 4; i++) {
  35.         if (N[3][i]<min) {
  36.             min = N[3][i];
  37.         }
  38.     }
  39.     for (int k = 0; k < 4; k++) {
  40.         if (N[3][k] == min) {
  41.             index = k;
  42.             break;
  43.         }
  44.     }
  45.     cout<<"Минимум "<<min<<endl<<"Индекс столбца который содержит минимум "<<index<<"\n";
  46.  
  47.     //Задание 2 : б) 3 столбец. Максимальный элемент. По строкам. Самая нижняя.
  48.     int max = N[0][2];
  49.     index = 0;
  50.     for (int i = 0 ; i < 5; i++) {
  51.         if (N[i][2] > max) {
  52.             max = N[i][2];
  53.         }
  54.     }
  55.     for (int i = 0; i<5; i++) {
  56.         if (N[i][2] == max)
  57.         {
  58.             index = i;
  59.         }
  60.     }
  61.     cout<<"Максимум "<<max<<endl<<"Индекс столбца который содержит максимум "<<index<<"\n";
  62.  
  63.     //Задание 3
  64.     int M[7][7]; //Создаём и заполняем двухмерный массив
  65.     for (int i = 0; i<7; i++) {
  66.         for (int j = 0; j<7; j++) {
  67.             M[i][j] = rand() % 30 - 15;
  68.             // cout<<N[i][j]<<endl;
  69.         }
  70.     }
  71.     int cf = 0;
  72.     min = M[6][0];
  73.     for (int i = 6; i > 2; i--) {
  74.         if (cf == 6) {
  75.             break;
  76.         }
  77.         for (int j = 0+cf; 6-cf >= 0; j++) {
  78.             if (M[i][j] < min) {
  79.                 min = M[i][j];
  80.             }
  81.         }
  82.         cf++;
  83.     }
  84.     cout<<"Минимум "<<min<<"\n";
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment