Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 KB | None | 0 0
  1. using System;
  2.  
  3.     class Program
  4.     {
  5.         static int input()
  6.         {
  7.             int N;
  8.             Console.WriteLine("Введите значение N - количство строк в массиве");
  9.             while (!int.TryParse(Console.ReadLine(), out N) || N < 1)
  10.             {
  11.                 Console.ForegroundColor = ConsoleColor.Red;
  12.                 Console.WriteLine("Вы ввели невнерный форматвходных данных\nПожалуйста, повторите ввод");
  13.                 Console.ResetColor();
  14.             }
  15.             return N;
  16.         }
  17.         static void Main(string[] args)
  18.         {
  19.             int N;
  20.             do
  21.             {
  22.  
  23.                 N = input();
  24.                 Methods array = new Methods(N);
  25.                 array.Print_array();
  26.  
  27.                 Console.WriteLine("Для выхода из программы нажмите Esc");
  28.             } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
  29.         }
  30.     }
  31. class Methods
  32. {
  33.     public int[][] my_array;
  34.     Random rnd = new Random();
  35.     int new_value;
  36.     public Methods(int N)
  37.     {
  38.         my_array = new int[N][];
  39.         for (int i = 0; i < N; i++)
  40.         {
  41.             my_array[i] = new int[0];
  42.             new_value = -1;
  43.             while (new_value != 0)
  44.             {
  45.                 new_value = rnd.Next(0, 6);
  46.                 Array.Resize(ref my_array[i], my_array[i].Length + 1);
  47.                 my_array[i][my_array[i].Length - 1] = new_value;
  48.                 Console.Write(my_array[i][my_array[i].Length - 1] + "  ");
  49.             }
  50.             Console.WriteLine();
  51.  
  52.         }
  53.  
  54.     }
  55.  
  56.     public void Print_array()
  57.     {
  58.         foreach(var x in my_array)
  59.         {
  60.             foreach(var y in x)
  61.             {
  62.                 Console.Write(y+" ");
  63.             }
  64.             Console.WriteLine();
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement