int n = 5; int m = 5;
int[,] mas = new int[n, m];
int[,] masb = new int[n,m];
int[] diag = new int[n];
Random rd = new Random();
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
mas[i, j] = rd.Next(100) - 5;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
richTextBox1.AppendText(String.Format("{0,3}", mas[i, j]));
diag[i] = mas[i, i];
richTextBox1.AppendText(Environment.NewLine);
}
int max = diag.Max();
int min = diag.Min();
for (int i = 0; i<n; i++)
{
for(int j=0; j<m; j++)
{
masb[i, j] = min <= mas[i, j] && mas[i, j] <= max ? mas[i, j] : -1;
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
richTextBox1.AppendText(String.Format("{0,3}", masb[i, j]));
richTextBox1.AppendText(Environment.NewLine);
}