Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <ctime>
- using namespace std;
- int main()
- {
- srand(time(0));
- int x, a, b, n, m;
- long long result = 1;
- bool flag = false;
- cout << "Enter x: ";
- cin >> x;
- n = pow(4, x);
- m = pow(3, x);
- cout << "Enter a: ";
- cin >> a;
- cout << "Enter b: ";
- cin >> b;
- int** matrix = new int* [n];
- cout << "Generated matrix: " << endl;
- for (int i = 0; i < n; i++)
- {
- matrix[i] = new int[m];
- for (int j = 0; j < m; j++)
- {
- matrix[i][j] = rand() % 10 - 5;
- cout << setw(5) << matrix[i][j];
- if (matrix[i][j] < a || matrix[i][j] > b)
- {
- flag = true;
- result *= matrix[i][j];
- }
- }
- cout << endl;
- }
- if (flag)
- cout << "The product of matrix elements lying outside the interval [" << a << ", " << b << "]: " << result << endl;
- else
- cout << "Elements outside the interval [" << a << ", " << b << "]" << " do not exist!" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment