alexandrheathen

Untitled

Nov 1st, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.03 KB | None | 0 0
  1. using System;
  2.  
  3. namespace LabCDM02
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] pluralityA, pluralityB;
  10.             int lengthArr;
  11.  
  12.             Console.Write("Введите количетсво элементов множества А: ");
  13.             lengthArr = int.Parse(Console.ReadLine());
  14.  
  15.             pluralityA = new int[lengthArr];
  16.  
  17.             Console.WriteLine("Множество А");
  18.             for (int i = 0; i < lengthArr; i++)
  19.             {
  20.                 Console.Write($"Элемент №{i + 1} -> ");
  21.                 pluralityA[i] = Int32.Parse(Console.ReadLine());
  22.             }
  23.  
  24.  
  25.             Console.Write("Введите количетсво элементов множества B: ");
  26.             lengthArr = int.Parse(Console.ReadLine());
  27.             pluralityB = new int[lengthArr];
  28.  
  29.             Console.WriteLine("Множество B");
  30.             for (int i = 0; i < lengthArr; i++)
  31.             {
  32.                 Console.Write($"Элемент №{i + 1} -> ");
  33.                 pluralityB[i] = int.Parse(Console.ReadLine());
  34.             }
  35.  
  36.             NewC(pluralityA, pluralityB);
  37.         }
  38.  
  39.         static void NewC(int[] plurA, int[] plurB)
  40.         {
  41.             int mark = -1;
  42.             Console.WriteLine("Матрица сотношений:");
  43.             for(int i = 0; i < plurA.Length; i++)
  44.             {
  45.                 for (int j = 0; j < plurB.Length; j++)
  46.                 {
  47.                     try
  48.                     {
  49.                         if ((2 * plurA[i] + 1) % plurB[i] == 0)
  50.                             mark = 1;
  51.                         else
  52.                             mark = 0;
  53.                         Console.Write($"{mark,3}");
  54.                     }
  55.                     catch(DivideByZeroException)
  56.                     {
  57.                         Console.WriteLine("Деление на 0.");
  58.                     }
  59.                 }
  60.                 Console.WriteLine();
  61.             }
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment