Advertisement
kxcoze

lab22_8_1

Sep 6th, 2020
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <time.h>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     setlocale(LC_ALL, "rus");
  10.     srand(time(NULL));
  11.     string ans = "";
  12.     int n, data[100][100], k1, k2, cntk1 = 0, cntk2 = 0;
  13.     cout << "Введите n: ";
  14.     cin >> n;
  15.  
  16.     cout << "Исходный матрица: " << endl;
  17.     for (int i = 0; i < n; i++) {
  18.         for (int j = 0; j < n; j++) {
  19.             data[i][j] = rand() % 20 - 10;
  20.             cout << data[i][j] << ' ';
  21.         }
  22.         cout << endl;
  23.     }
  24.     cout << endl;
  25.  
  26.     cout << "Введите k1: ";
  27.     cin >> k1;
  28.    
  29.     cout << "Введите k2: ";
  30.     cin >> k2;
  31.  
  32.     for (int i = 0; i < n; i++) {
  33.         for (int j = 0; j < n; j++) {
  34.             if (data[i][j] > k1)
  35.                 cntk1++;
  36.             if (data[i][j] < k2)
  37.                 cntk2++;
  38.         }
  39.     }
  40.  
  41.     if (cntk1 > cntk2)
  42.         ans = "больше";
  43.     else if (cntk1 < cntk2)
  44.         ans = "меньше";
  45.     else
  46.         ans = "равно";
  47.  
  48.     cout << "Кол-во элементов превышающих k1 (" << cntk1 << ") " << ans << " чем не превышающих k2(" << cntk2 << ") ." << endl;
  49.    
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement