Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. Console.Write("n= ");
  2.             int n = int.Parse(Console.ReadLine());
  3.             int[,] a = new int[n,n];
  4.             for (int row = 0; row < n; row++)
  5.             {
  6.                 for (int col = 0; col < n; col++)
  7.                 {
  8.                     a[row, col] = int.Parse(Console.ReadLine());
  9.                 }
  10.             }
  11.  
  12.             int[] c = new int[n * n];
  13.             int k = 0;
  14.             for (int row = 0; row < n; row++)
  15.             {
  16.                 if(row%2==0)
  17.                 {
  18.                
  19.                     for (int col = 0; col < n; col++)
  20.                     {
  21.                         c[k] = a[row, col];
  22.                         k++;
  23.                     }
  24.             }
  25.                 else
  26.                 {
  27.                     for (int col = n-1; col >= 0; col--)
  28.                     {
  29.                         c[k] = a[row, col];
  30.                         k++;
  31.                     }
  32.                 }
  33.             }
  34.                
  35.                Console.WriteLine("Елементите на c са: ");
  36.             for (int i = 0; i < k; i++)
  37.             {
  38.                 Console.Write(c[i] + " ");
  39.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement