Bob103

C#_for_Nigga_(VI-3-№8)

Apr 19th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.10 KB | None | 0 0
  1. class Program
  2.     {
  3.         //GetLength(1)-столбцы
  4.  
  5.         static void Main(string[] args)
  6.         {
  7.             /*************ИНИЦИАЛИЗАЦИЯ***************/
  8.             Console.Write("Enter ebaniy razmer strok:");
  9.             int n = int.Parse(Console.ReadLine());
  10.             Console.Write("Enter ebaniy razmer stolbov:");
  11.             int m = int.Parse(Console.ReadLine());
  12.             int[,] mas = new int[n, m];
  13.  
  14.             /****************ВВОД*********************/
  15.             for (int i = 0; i < mas.GetLength(0); i++)
  16.             {
  17.                 for (int j = 0; j < mas.GetLength(1); j++)
  18.                 {
  19.                     Console.Write("mas[{0},{1}]= ", i, j);
  20.                     mas[i, j] = int.Parse(Console.ReadLine());
  21.                 }
  22.             }
  23.  
  24.             int[,] mas2 = (int[,])mas.Clone();//создали второй массив
  25.  
  26.             /*********ПОШЛА_ЖАРА******************/
  27.             if (mas.GetLength(1) % 2 == 0)
  28.             {
  29.                 for (int i = 0; i < mas.GetLength(0); i++)
  30.                 {
  31.                     for (int j = 0; j < mas.GetLength(1); j++)
  32.                     {
  33.                         mas[i, j / 2] = mas2[i, (j / 2) + 1];
  34.                         mas[i, (j / 2) + 1] = mas2[i, (j / 2)];
  35.                     }
  36.  
  37.                 }
  38.             }
  39.             else
  40.             {
  41.                 for (int i = 0; i < mas.GetLength(0); i++)
  42.                 {
  43.                     for (int j = 0; j < mas.GetLength(1); j++)
  44.                     {
  45.                         mas[i, 0] = mas2[i, (byte)Math.Round(j / 2.0)];
  46.                         mas[i, (byte)Math.Round(j / 2.0)] = mas2[i, 0];
  47.                     }
  48.                 }
  49.             }
  50.  
  51.             /********************ВЫВОД*****************/
  52.             for (int i = 0; i < mas.GetLength(0); i++)
  53.             {
  54.                 for (int j = 0; j < mas.GetLength(1); j++)
  55.                 {
  56.                 Console.Write("{0} ", mas[i, j]);
  57.                 }
  58.  
  59.                 Console.WriteLine();
  60.             }
  61.  
  62.  
  63.         }
  64.     }
Advertisement
Add Comment
Please, Sign In to add comment