using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int n = 10; int m = 10; string s1=""; //записываем в неё номера столбцов подходящих по условию int[,] mas = new int[n, m]; Random rn = new Random(); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) mas[i, j] = rn.Next(10)+1;//+1 чтобы не появлялся 0 Console.WriteLine("Массив до изменений:"); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) Console.Write(String.Format("{0,3}", mas[i, j])); Console.WriteLine(); } Console.WriteLine("Столбцы подходящие условию"); for (int i = 0; i < m; i++) { if (Convert.ToInt32(mas[0, i]) % 2 != 0) { if (Convert.ToInt32(mas[n-1, i]) % 2 == 0) { Console.WriteLine("Столбец " + i); s1 = s1 + Convert.ToString(i); } } } if (s1.Length > 1) { for (int i = 0; i < s1.Length-1; i++) { for (int j = 0; j < n; j++) { int el =Convert.ToInt32(Convert.ToString(s1[i])); int tmp = mas[j, Convert.ToInt32(Convert.ToString(s1[i]))]; mas[j, Convert.ToInt32(Convert.ToString(s1[i]))] = mas[j, Convert.ToInt32(Convert.ToString(s1[i+1]))]; mas[j, Convert.ToInt32(Convert.ToString(s1[i+1]))] = tmp; } } Console.WriteLine("Массив после изменений:"); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) Console.Write(String.Format("{0,3}", mas[i, j])); Console.WriteLine(); } } Console.ReadLine(); } } }