myname0

практикум6_III_14

Oct 14th, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. static int[,] Create(int n)
  2.         {
  3.             Console.WriteLine("Enter the array: ");
  4.             int[,] mas = new int[n, n];
  5.             String enterString;
  6.             String[] massiveString;
  7.             for (int i = 0; i < n; i++)
  8.             {
  9.                 enterString = Console.ReadLine();
  10.                 massiveString = enterString.Split(new Char[] { ' ' });
  11.                 for (int j = 0; j < n; j++)
  12.                 {
  13.                     mas[i, j] = int.Parse(massiveString[j]);
  14.                 }
  15.             }
  16.             return mas;
  17.         }
  18.         static void Print(int n, int [,] mas)
  19.         {
  20.             for (int i = 0; i < n; i++)
  21.             {
  22.                 if (i % 2 == 0)
  23.                 {
  24.                     for (int j = 0; j < n; j++)
  25.                         Console.Write("{0} ", mas[i,j]);
  26.                 }
  27.                 else
  28.                 {
  29.                     for (int j = n-1; j >= 0; j--)
  30.                         Console.Write("{0} ", mas[i, j]);
  31.                 }
  32.                 Console.WriteLine();
  33.             }
  34.         }
  35.  
  36.         static void Main(string[] args)
  37.        
  38.        {
  39.            Console.Write("Enter n: ");
  40.            int n = int.Parse(Console.ReadLine());
  41.            int [,] mas = new int [n,n];
  42.            mas = Create(n);
  43.            Console.WriteLine("The output of the array:");
  44.            Print(n, mas);
  45.         }
Advertisement
Add Comment
Please, Sign In to add comment