Advertisement
MChaos

// Выводим и Заполняем массив 0 и только один эле

Sep 29th, 2022
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. // Online C# Editor for free
  2. // Write, Edit and Run your C# code using C# Online Compiler
  3.  
  4. using System;
  5.  
  6. public class ArrayXY
  7. {
  8.     public static void Main(string[] args)
  9.     {
  10.         Random rando = new Random();
  11.         int[,] array = new int[6, 6];
  12.             // Выводим и Заполняем массив 0 и 1
  13.             for (int y = 0; y < 6; y++)
  14.             {
  15.                 for (int x = 0; x < 6; x++)
  16.                 {
  17.                     array[x,  y] = rando.Next(0, 2);
  18.                     Console.Write(array[x, y] + " ");
  19.                 }
  20.                 Console.WriteLine();
  21.             }
  22.            
  23.              Console.WriteLine();
  24.              Console.WriteLine();
  25.              
  26.              // Выводим и Заполняем массив 0 и только один элемент 1
  27.              int[,] array2 = new int[6, 6];
  28.              int i = rando.Next(0, 6);
  29.              int j = rando.Next(0, 6);
  30.              array2[i,  j] = 1;
  31.              
  32.              for (int y = 0; y < 6; y++)
  33.             {
  34.                 for (int x = 0; x < 6; x++)
  35.                 {
  36.                     Console.Write(array2[x, y] + " ");
  37.                 }
  38.                 Console.WriteLine();
  39.             }
  40.              
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement