Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Z_3
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Title = "Laba4_3";
- Console.WriteLine("Вывести элементы матрицы на экран в следующем порядке:");
- Console.Write("Ведите натуральное число, n= ");
- int n = EnterInt();
- Console.Write("Ведите натуральное число, m= ");
- int m = EnterInt();
- int[,] arr = new int[n, m];
- FillingArray(arr);
- Display1(arr);
- Console.WriteLine("************");
- Display2(arr);
- Console.ReadKey();
- }
- static void FillingArray(int[,] arr)
- {
- Random Rand = new Random();
- for (int i = 0; i < arr.GetLength(0); i++)
- {
- for (int j = 0; j < arr.GetLength(1); j++)
- {
- arr[i, j] = Rand.Next(9);
- }
- }
- }
- static void Display1(int[,] arr)
- {
- for (int i = 0; i < arr.GetLength(0); i++)
- {
- for (int j = 0; j < arr.GetLength(1); j++)
- {
- Console.Write("{0} ", arr[i, j]);
- }
- Console.WriteLine();
- }
- }
- static void Display2(int[,] arr)
- {
- for (int i = arr.GetLength(0) - 1; i >= 0; i--)
- {
- for (int j = 0; j < arr.GetLength(1); j++)
- {
- Console.Write("{0} ", arr[i, j]);
- }
- if (i != 0)
- {
- Console.WriteLine();
- i--;
- for (int j = arr.GetLength(1) - 1; j >= 0; j--)
- {
- Console.Write("{0} ", arr[i, j]);
- }
- Console.WriteLine();
- }
- }
- }
- static int EnterInt()
- {
- int value;
- bool result = false;
- result = int.TryParse(Console.ReadLine(), out value);
- if (result == false)
- {
- do
- {
- Console.Write("Некорректные данные. Введите заново: ");
- result = int.TryParse(Console.ReadLine(), out value);
- }
- while (!result);
- }
- return value;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement