#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <ctime>
using namespace std;
bool find(int m, int n, int ** mas) {
for (int i = 0; i<m; i++) {
for (int j = 0; j<n; j++) {
if (mas[i][j]<0) return true;
}
}
return false;
}
int main() {
int m,n;
srand(time(0));
cout << "Введите размер матрицы MxN" << endl << "M=";
cin >> m;
cout << endl << "N=";
cin >> n;
cout << endl << "Сгенерируем матрицу и проверим, встречаются ли среди её эллементов отрицательные" << endl;
int **mas = new int*[m];
for (int i = 0; i<m; i++)
{
mas[i] = new int[n];
for (int j = 0; j<n; j++)
{
mas[i][j] = rand() % 20 - 10;
cout << mas[i][j] << " ";
}
cout << endl;
}
if (find(m, n, mas) == true) cout << "В данной матрице встречаются отрицательные элементы.";
else cout << "В данной матрице не встречаются отрицательные элементы.";
for (int i = 0; i < m; i++)
{
delete[] mas[i];
}
delete[] mas;
}
ICAgICNpbmNsdWRlIDxjc3RkaW8+CiAgICAjaW5jbHVkZSA8aW9zdHJlYW0+CiAgICAjaW5jbHVkZSA8Y3N0ZGxpYj4KICAgICNpbmNsdWRlIDxjbWF0aD4KICAgICNpbmNsdWRlIDxjdGltZT4KICAgICAKICAgIHVzaW5nIG5hbWVzcGFjZSBzdGQ7CiAgICAgCiAgICBib29sIGZpbmQoaW50IG0sIGludCBuLCBpbnQgKiogbWFzKSB7CiAgICAJZm9yIChpbnQgaSA9IDA7IGk8bTsgaSsrKSB7CiAgICAJCWZvciAoaW50IGogPSAwOyBqPG47IGorKykgewogICAgCQkJaWYgKG1hc1tpXVtqXTwwKSByZXR1cm4gdHJ1ZTsKICAgIAkJfQogICAgCX0KICAgIAlyZXR1cm4gZmFsc2U7CiAgICB9CiAgICAgCiAgICBpbnQgbWFpbigpIHsKICAgIAlpbnQgbSxuOwogICAgCXNyYW5kKHRpbWUoMCkpOwogICAgCWNvdXQgPDwgItCS0LLQtdC00LjRgtC1INGA0LDQt9C80LXRgCDQvNCw0YLRgNC40YbRiyBNeE4iIDw8IGVu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