lovelyvook

Unit_36

Jul 10th, 2024
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace Ijunior
  5. {
  6.     internal class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int arrayCapacity = 10;
  11.             int[] array01 = new int[arrayCapacity];
  12.             int[] array02 = new int[arrayCapacity];
  13.             Random random = new Random();
  14.  
  15.             List<int> list = new List<int>();
  16.  
  17.             FillArray(array01, random);
  18.             FillArray(array02, random);
  19.  
  20.             ShowArray(array01);
  21.             ShowArray(array02);
  22.  
  23.             FillList(array01, list);
  24.             FillList(array02, list);
  25.  
  26.             ShowList(list);
  27.         }
  28.  
  29.         static void FillArray(int[] array, Random random)
  30.         {
  31.             int minRandomNumber = 1;
  32.             int maxRandomNumber = 6;
  33.  
  34.             for (int i = 0; i < array.Length; i++)
  35.             {
  36.                 array[i] = random.Next(minRandomNumber, maxRandomNumber);
  37.             }
  38.         }
  39.  
  40.         static void ShowArray(int[] array)
  41.         {
  42.             foreach (int number in array)
  43.             {
  44.                 Console.Write(number + " ");
  45.             }
  46.  
  47.             Console.WriteLine();
  48.         }
  49.  
  50.         static void FillList(int[] array, List<int> list)
  51.         {
  52.             for (int i = 0; i < array.Length; i++)
  53.             {
  54.                 if (list.Contains(array[i]) == false)
  55.                 {
  56.                     list.Add(array[i]);
  57.                 }
  58.             }
  59.         }
  60.  
  61.         static void ShowList(List<int> list)
  62.         {
  63.             foreach(int number in list)
  64.             {
  65.                 Console.Write(number + " ");
  66.             }
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment