internal class Program
{
static void Main(string[] args)
{
// # 6. Проверить, есть ли столбец,
// в котором равное количество положительных
// и отрицательных элементов
Console.WriteLine("Введите количество строк:");
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Введите количество столбцов:");
int m = Convert.ToInt32(Console.ReadLine());
int[,] a = new int[n, m];
Random rnd = new Random();
// Заполнение матрицы случайными числами
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
a[i, j] = rnd.Next(-10, 11);
}
}
// Вывод матрицы
Console.WriteLine("\nМатрица:");
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
Console.Write($"{a[i, j],5}");
}
Console.WriteLine();
}
bool found = false;
// Проверка каждого столбца
for (int j = 0; j < m; j++)
{
int positive = 0;
int negative = 0;
for (int i = 0; i < n; i++)
{
if (a[i, j] > 0)
positive++;
if (a[i, j] < 0)
negative++;
}
if (positive == negative)
{
found = true;
break;
}
}
// Вывод результата
if (found)
Console.WriteLine("\nЕсть столбец с равным количеством положительных и отрицательных элементов");
else
Console.WriteLine("\nНет такого столбца");
Console.ReadKey();
}
}