Advertisement
filin

laba_4_z_3_new

Oct 20th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Z_3
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.Title = "Laba4_3";
  14.             Console.WriteLine("Вывести элементы матрицы на экран в следующем порядке:");
  15.             Console.Write("Ведите натуральное число, n= ");
  16.             int n = EnterInt();
  17.             Console.Write("Ведите натуральное число, m= ");
  18.             int m = EnterInt();
  19.             int[,] arr = new int[n, m];
  20.             FillingArray(arr);
  21.             Display1(arr);
  22.             Console.WriteLine("************");
  23.             Display2(arr);
  24.             Console.ReadKey();
  25.         }
  26.         static void FillingArray(int[,] arr)
  27.         {
  28.             Random Rand = new Random();
  29.             for (int i = 0; i < arr.GetLength(0); i++)
  30.             {
  31.                 for (int j = 0; j < arr.GetLength(1); j++)
  32.                 {
  33.                     arr[i, j] = Rand.Next(9);
  34.                 }
  35.             }
  36.         }
  37.         static void Display1(int[,] arr)
  38.         {
  39.             for (int i = 0; i < arr.GetLength(0); i++)
  40.             {
  41.                 for (int j = 0; j < arr.GetLength(1); j++)
  42.                 {
  43.                     Console.Write("{0} ", arr[i, j]);
  44.                 }
  45.                 Console.WriteLine();
  46.             }
  47.         }
  48.         static void Display2(int[,] arr)
  49.         {
  50.             for (int i =  arr.GetLength(0) - 1; i >= 0; i--)
  51.             {
  52.                 for (int j = 0; j < arr.GetLength(1); j++)
  53.                 {
  54.                     Console.Write("{0} ", arr[i, j]);
  55.                 }
  56.                 if (i != 0)
  57.                 {
  58.                     Console.WriteLine();
  59.                     i--;
  60.                     for (int j = arr.GetLength(1) - 1; j >= 0; j--)
  61.                     {
  62.                         Console.Write("{0} ", arr[i, j]);
  63.                     }
  64.                     Console.WriteLine();
  65.                 }
  66.             }
  67.         }
  68.         static int EnterInt()
  69.         {
  70.             int value;
  71.             bool result = false;
  72.             result = int.TryParse(Console.ReadLine(), out value);
  73.             if (result == false)
  74.             {
  75.                 do
  76.                 {
  77.                     Console.Write("Некорректные данные. Введите заново: ");
  78.                     result = int.TryParse(Console.ReadLine(), out value);
  79.                 }
  80.                 while (!result);
  81.             }
  82.             return value;
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement