Bob103

C#_4_(III-6)

Oct 6th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.86 KB | None | 0 0
  1. /*Поменять местами столбцы по правилу: первый с последним, второй с предпоследним и т.д*/
  2. class Program
  3.     {
  4.         static void setarray( int[,] arr)
  5.         {
  6.             for (int i = 0; i < arr.GetLength(0); i++)
  7.             {
  8.                 for (int j = 0; j < arr.GetLength(1); j++)
  9.                 {
  10.                     Console.Write("Arr[{0}][{1}]=", i, j);
  11.                     arr[i, j] = Convert.ToInt32(Console.ReadLine());
  12.                 }
  13.             }
  14.         }
  15.  
  16.         static void outarray(int [,] arr)
  17.         {
  18.             for (int i = 0; i < arr.GetLength(0); i++)
  19.             {
  20.                 for (int j = 0; j < arr.GetLength(1); j++)
  21.                 {
  22.                     Console.Write("{0} ", arr[i, j]);
  23.                 }
  24.                 Console.WriteLine();
  25.             }
  26.         }
  27.  
  28.         static void changest(int[,] arr)
  29.         {
  30.             for (int i = 0; i < arr.GetLength(0);i++)
  31.             for (int j = 0; j < arr.GetLength(1)/2;j++)
  32.             {
  33.                     int x = arr[i, j];
  34.                     arr[i, j] = arr[i, (arr.GetLength(1) - 1) - j];
  35.                     arr[i, (arr.GetLength(1) - 1) - j] = x;
  36.                 }
  37.         }
  38.  
  39.  
  40.         static void Main(string[] args)
  41.         {
  42.             Console.Write("Введите кол-во строчек: ");
  43.             int s = Convert.ToInt32(Console.ReadLine());
  44.             Console.Write("Введите кол-во столбцов: ");
  45.             int st = Convert.ToInt32(Console.ReadLine());
  46.             int[,] arr = new int [s,st];
  47.             setarray(arr);
  48.             Console.WriteLine("До:");
  49.             outarray(arr);
  50.             Console.WriteLine();
  51.             Console.WriteLine("После:");
  52.             changest(arr);
  53.             outarray(arr);
  54.  
  55.         }
  56.     }
Advertisement
Add Comment
Please, Sign In to add comment