AmidamaruZXC

Untitled

Feb 13th, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     srand(time(0));
  10.     int x, a, b, n, m;
  11.     long long result = 1;
  12.     bool flag = false;
  13.     cout << "Enter x: ";
  14.     cin >> x;
  15.     n = pow(4, x);
  16.     m = pow(3, x);
  17.     cout << "Enter a: ";
  18.     cin >> a;
  19.     cout << "Enter b: ";
  20.     cin >> b;
  21.     int** matrix = new int* [n];
  22.     cout << "Generated matrix: " << endl;
  23.     for (int i = 0; i < n; i++)
  24.     {
  25.         matrix[i] = new int[m];
  26.         for (int j = 0; j < m; j++)
  27.         {
  28.             matrix[i][j] = rand() % 10 - 5;
  29.             cout << setw(5) << matrix[i][j];
  30.             if (matrix[i][j] < a || matrix[i][j] > b)
  31.             {
  32.                 flag = true;
  33.                 result *= matrix[i][j];
  34.             }
  35.         }
  36.         cout << endl;
  37.     }
  38.     if (flag)
  39.         cout << "The product of matrix elements lying outside the interval [" << a << ", " << b << "]: " << result << endl;
  40.     else
  41.         cout << "Elements outside the interval [" << a << ", " << b << "]" << " do not exist!" << endl;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment