Advertisement
aspire12

02.CommonElements

Feb 8th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. namespace _02.Common_Elements
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             //Write a program, which prints common elements in two arrays. You have to compare the elements of the second array to the elements of the first.
  11.  
  12.  
  13.             string[] array1 = Console.ReadLine().Split();
  14.             string[] array2 = Console.ReadLine().Split();
  15.             StringBuilder result = new StringBuilder();
  16.            
  17.             for (int i = 0; i < array1.Length; i++)
  18.             {
  19.                 for (int j = 0; j < array2.Length; j++)
  20.                 {
  21.                     if (array1[i] == array2[j])
  22.                     {
  23.                         result.Append(array2[j] + " ");
  24.                     }
  25.                 }
  26.             }
  27.             Console.WriteLine(result);
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement