1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | using System; int rows, columns; Console.Write( "Введите кол-во строк " ); rows = Int32.Parse(Console.ReadLine()); Console.Write( "Введите кол-во столбцов " ); columns = Int32.Parse(Console.ReadLine()); Random rnd = new Random(); int [,] arrayA = new int [rows, columns]; for ( int y = 0; y < rows; y++) { for ( int x = 0; x < columns; x++) { arrayA[y, x] = rnd.Next(100); } } Console.WriteLine( "Массив A:" ); Print(arrayA, rows, columns); int [,] arrayB = new int [rows, columns]; for ( int y = 0; y < rows; y++) { arrayB[y, 2] = arrayA[y, 2]; } Console.WriteLine( "Массив B:" ); Print(arrayB, rows, columns); static void Print( int [,] array, int rows, int columns) { for ( int y = 0; y < rows; y++) { for ( int x = 0; x < columns; x++) { Console.Write(array[y, x] + " " ); } Console.WriteLine(); } } |
Вариант 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | using System; int rows, columns; Console.Write( "Введите кол-во строк " ); rows = Int32.Parse(Console.ReadLine()); Console.Write( "Введите кол-во столбцов " ); columns = Int32.Parse(Console.ReadLine()); Random rnd = new Random(); int [,] arrayA = new int [rows, columns]; Console.WriteLine( "Массив A:" ); var y = 0; while (y < rows) { var x = 0; while (x < columns) { arrayA[y, x] = rnd.Next(100); x++; } y++; } Print(arrayA, rows, columns); int [,] arrayB = new int [rows, columns]; Console.WriteLine( "Массив B:" ); y = 0; while (y < rows) { arrayB[y, 1] = arrayA[y, 1]; y++; } Print(arrayB, rows, columns); static void Print( int [,] array, int rows, int columns) { var y = 0; while (y < rows) { var x = 0; while (x < columns) { Console.Write(array[y, x] + " " ); x++; } y++; Console.WriteLine(); } } |